how to set Maximum Length In Multiline Mode of TextBox
-
i have try using this code.when i write 100 char (max Length) contineuosly then it will work..but when i m copy some text and paste on that text box at that time it will not be dispaly the error msg.
function textboxMultilineMaxNumber(txt,maxLen){
try{
if(txt.value.length > (maxLen-1))return false;
}catch(e){
}
}
runat="server" Height="103px" MaxLength="100" Width="166px" onkeypress='return textboxMultilineMaxNumber(this,100)' TextMode="MultiLine"Jintal Patel
-
i have try using this code.when i write 100 char (max Length) contineuosly then it will work..but when i m copy some text and paste on that text box at that time it will not be dispaly the error msg.
function textboxMultilineMaxNumber(txt,maxLen){
try{
if(txt.value.length > (maxLen-1))return false;
}catch(e){
}
}
runat="server" Height="103px" MaxLength="100" Width="166px" onkeypress='return textboxMultilineMaxNumber(this,100)' TextMode="MultiLine"Jintal Patel
-
i have try using this code.when i write 100 char (max Length) contineuosly then it will work..but when i m copy some text and paste on that text box at that time it will not be dispaly the error msg.
function textboxMultilineMaxNumber(txt,maxLen){
try{
if(txt.value.length > (maxLen-1))return false;
}catch(e){
}
}
runat="server" Height="103px" MaxLength="100" Width="166px" onkeypress='return textboxMultilineMaxNumber(this,100)' TextMode="MultiLine"Jintal Patel
If you want ot set maximum length of a multiline textbox, You can use the following code in page load. System.Text.StringBuilder jScriptStr2 = new System.Text.StringBuilder(); jScriptStr2.Append(""); jScriptStr2.Append("function limitText (textObj, maxCharacters){"); jScriptStr2.Append("if (textObj.innerText.length >= maxCharacters){"); jScriptStr2.Append("if ((event.keyCode >= 32 && event.keyCode <= 126) || (event.keyCode >= 128 && event.keyCode <= 254)){"); jScriptStr2.Append("event.returnValue = false;"); jScriptStr2.Append("}}}"); Page.RegisterStartupScript("textLimiter", jScriptStr2.ToString()); And In Html of textbox add OnKeyDown="limitText (this, 500);"
Thanks & Regards Mishra
-
maxlength does not restricts the user to type only that much length which is defined in the properties in asp.net.