?
Solved

Maxlength for mulitiple line text box

Posted on 2006-04-18
11
Medium Priority
?
897 Views
Last Modified: 2008-02-01
Is there any way to set maxlength for multipleline text box? <asp:textbox textmode=multiline....
Thanks for help.
0
Comment
Question by:CochiseCounty
10 Comments
 
LVL 23

Expert Comment

by:naveenkohli
ID: 16478234
0
 
LVL 6

Expert Comment

by:fizch
ID: 16478237
You have to write client side code to check the length, or use a custom validator
0
 
LVL 16

Expert Comment

by:MikeMCSD
ID: 16478459
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:tusharashah
ID: 16478488
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
 
LVL 6

Expert Comment

by:fizch
ID: 16478549
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
 
LVL 18

Expert Comment

by:tusharashah
ID: 16478622
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
 
LVL 6

Expert Comment

by:fizch
ID: 16478685
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
 

Author Comment

by:CochiseCounty
ID: 16478784
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
 
LVL 6

Expert Comment

by:fizch
ID: 16478867
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
 

Accepted Solution

by:
GranMod earned 0 total points
ID: 16516788
Closed, 125 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Integration Management Part 2
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question