Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I set Textbox max length when using multiline? 1

Status
Not open for further replies.

joelwenzel

Programmer
Jun 28, 2002
448
How can I set the textbox's maximum length when using multiline? For single line, the maxlength property works but it does not apply to multiline. I've tried using 50 columns and 3 rows (for a character length of 150 but I am having no luck)

any ideas?
 
As Jim points out, you can only do this via javascript, however, there is a slightly smaller script you can use (although it may be best to check in the javascript forum for the best way of doing what you need). In this example I've registered all the necessary code server-side:
Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Page.RegisterClientScriptBlock("limittextarea", "<script>function setTextAreaLength(Object, MaxLength){return (Object.value.length <= MaxLength);}</script>")
        TextBox1.Attributes.Add("onkeypress", "return setTextAreaLength(this, 150);")
    End Sub


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top