Maxlength for mulitiple line text box

Is there any way to set maxlength for multipleline text box? <asp:textbox textmode=multiline....
Thanks for help.
CochiseCountyAsked:
Who is Participating?
 
GranModCommented:
Closed, 125 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0
 
naveenkohliCommented:
0
 
fizchCommented:
You have to write client side code to check the length, or use a custom validator
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
MikeMCSDCommented:
0
 
tusharashahCommented:
You can add following code in your Page_Load event for multiline textbox:

  TextBox1.Attributes.Add("onkeypress","if(this.value.length>=" + TextBox1.MaxLength + ") return false;");

0
 
fizchCommented:
tusharashah has a good point there. That will stop the input all together if it is exceeding the max length. The only problem with that is because the MaxLength attribute of the textarea field is an invalid attribute, you might not get a value back from TextBox1.MaxLength which means you would have to hard code the length.
0
 
tusharashahCommented:
TextArea is different then MultiLine TextBox
Not sure about the TextArea, but MaxLength is allowed in Multiline textbox.. so there's no worry over there..

-tushar
0
 
fizchCommented:
A multiline textbox is rendered as a textarea. The textarea does not support the maxlength attribute. The only difference you see in programming it is that the multiline textbox is a server control while the textarea is an html control.

I'm not saying that it is not possible. I'm just saying becuase of my experience with text area fields, it is something to take note of, and I'm offering a work around in case that does end up being a problem.
0
 
CochiseCountyAuthor Commented:
Hi everyone,
here is what I did and it works (from http://aspnet.4guysfromrolla.com/articles/073102-1.aspx)

Code behind
Sub LengthCheck(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
        If Len(txtComments.Text) > 250 Then
            args.IsValid = False
        Else
            args.IsValid = True
        End If
    End Sub
aspx page
<asp:CustomValidator runat="server" id="cvComments"
ControlToValidate="txtComments"
OnServerValidate="LengthCheck"
ErrorMessage="Exceed 250 characteres" Font-Bold=True />
0
 
fizchCommented:
That is pretty much the same thing I just posted for MikeMCSD's issue. Hopefully that works for him as well.

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21797284.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.