Monday, March 23, 2009

ASP.NET textbox multiline maxlength

Very useful and simple javascript if you want to protect a multiline text box from enterting too many characters!

function CheckCount(text,length)




      var maxlength = new Number(length); // Change number to your max length.


if(text.value.length > maxlength){


                text.value = text.value.substring(0,maxlength);


                alert(" Only " + maxlength + " characters allowed");



<asp:TextBox ID="textBox" onKeyUp="javascript:Count(this,100);" onChange="javascript:Count(this,100);"  TextMode=MultiLine Columns="5" Rows="5" runat=server>


Or something like that...

No comments:

Post a Comment