Textbox maxlength

Posted on 2004-11-18
Last Modified: 2012-08-14
I want to set the maxlength property of a textbox with the textmode as multiline.  How can i use the maxlength property to set my textbox in such a way it does not let the user to enter more than the maxlength property. Again it is a multiline textbox.

Question by:miyengar
    LVL 9

    Expert Comment

    by:Rodney Helsens
    Restricting length of the text in Multiline textbox is not supported in ASP.NET Web control, you can accomplish the maxlength property by using a RegularExpression Validator... check the link below.

    taken from
    LVL 9

    Expert Comment

    by:Rodney Helsens

    Author Comment

    I want to use custom validator to check the length.  Can someone help me with the code
    LVL 12

    Accepted Solution

    You can use custom validator like this

    <asp:customvalidator id="CustomValidator1" runat="server" CssClass="instructionSmall" ControlToValidate="TextBox1" ErrorMessage="Maximum 5000 characters allowed." Display="Dynamic" ClientValidationFunction="ClientValidate"></asp:customvalidator>

    <script language="javascript">
                function ClientValidate(source,args) {
                      if(args.Value.length >= 5000)
                                args.IsValid = false;
                      else { args.IsValid = true; }

    Author Comment

    The above code works fine but had a question on that:
    5000  the max length is being hardcoded.  Instead of hard coding, in another textbox I want to enter maxlength which may vary each time and then use that value in my program rather than hardcoding 5000 as max length. Any solution on that. I appreciate ur help.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now