Posts Maxlength of multiline textbox in ASP.Net
Post
Cancel

Maxlength of multiline textbox in ASP.Net

Many times you need to restrict the number of character’s in multi-line textbox in asp.net. However the maxlength property does not helps in this case what you can do is use this javascript code to restrict the number of input characters in multiline textbox.

<script language=”javascript”>

function textboxMultilineMaxNumber(txt, maxLen) {

try {

if (txt.value.length > (maxLen – 1)) return false;

} catch (e) {

}

}

</script>

use javascript like this,

<asp:textbox id=”TextBox1″ runat=”server” Width=”232px” TextMode=”MultiLine” Height=”48px” style=”Z-INDEX: 104; LEFT: 136px; TOP: 336px”

onkeypress=”return textboxMultilineMaxNumber(this,10)”></asp:textbox>

This post is licensed under CC BY 4.0 by the author.