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 ?
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.
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)"