How To Set Maxlength For Multiline Textbox In Asp.Net

How To Set Maxlength For Multiline Textbox In Asp.Net

In this post we will learn How To Set Maxlength For Multiline Textbox In Asp.Net.Here we are using jQuery to achieve this.

Code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>How To Set Maxlength For Multiline Textbox In Asp.Net</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js">
</script>
<script type="text/javascript">
$(function() {
$('#mtxt').keypress(function(e) {
var txt = $(this).val();
if (txt.length > 100) {
e.preventDefault();
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>How To Set Maxlength For Multiline Textbox In Asp.Net</h2>
Enter Text:<asp:TextBox ID="mtxt" TextMode="MultiLine" runat="server" ></asp:TextBox>
</div>
</form>
</body>
</html>