Results 1 to 3 of 3

Thread: Set maxlength property on multiline textbox in Asp.net

  1. #1
    Join Date
    Dec 2008
    Posts
    9

    Set maxlength property on multiline textbox in Asp.net

    Hi all,

    In my Asp.net project,
    I have a textbox with TextMode set to MultiLine. I also have the MaxLength property of textbox set to 100. This maxlength value seems to get ignored as the user can enter unlimited characters.

    So how can i set the maxlength for Multiline textbox ?

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: Set maxlength property on multiline textbox in Asp.net

    When the TextMode property of textbox is set to Multiline, the MaxLength property wont be handled in controlling the maximum length of users inputs.

    The users can enter as much charaters as he wants in Multiline Textbox even MaxLength of this textbox is set to a particular value.
    Obviously, this is a bug of ASP.NET.

    For the solution to this problem you have to create your own function according to your logic to set the maxlength property of text box.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Set maxlength property on multiline textbox in Asp.net

    You can use this function.

    Code:
    function CheckLength(text,long) 
    
    {
    	var maxlength = new Number(long); // Change number to your max length.
    	if (text.value.length > maxlength)
           {
    		text.value = text.value.substring(0,maxlength);
    
    		alert(" Only " + long + " chars");
    
    	}
    }

    and use this function in the text box events as given below,

    onKeyUp="CheckLength(this,200)"
    onChange="CheckLength(this,200)"

Similar Threads

  1. Multiline screen fault in Sony Bravia KDL-32D3000 TV
    By ElroyDJ in forum Monitor & Video Cards
    Replies: 9
    Last Post: 14-01-2012, 02:21 AM
  2. Replies: 2
    Last Post: 20-08-2010, 01:23 AM
  3. vb.net multiline string
    By CAITLIN in forum Software Development
    Replies: 3
    Last Post: 13-07-2009, 12:51 PM
  4. How to set the maxlength of the textboxes dynamically
    By Sophia in forum Software Development
    Replies: 3
    Last Post: 18-03-2009, 12:00 AM
  5. How to lock a textbox need property through code.
    By rupak in forum Software Development
    Replies: 2
    Last Post: 27-02-2009, 10:50 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,065,126.88783 seconds with 16 queries