Please refer this code
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
var count = 0;
function TextBoxKeyPress(e) {
if (count < 10) {
if (e.keyCode == 13) {
count += 2;
}
else {
count += 1;
}
document.getElementById("remainingCharacters").innerHTML = "Remaining characters:" + (10 - count);
}
else {
var text = document.getElementById("<%=txtAddress.ClientID %>").value;
document.getElementById("<%=txtAddress.ClientID %>").value = text.substring(0, 9);
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" onkeypress="return TextBoxKeyPress(event);" />
<br />
Max length 10 character
<br />
<span id="remainingCharacters"></span>
<asp:Button Text="Save" OnClick="Save" runat="server" />
</div>
</form>
</body>
|</html>
C#
protected void Save(object sender, EventArgs e)
{
string address = this.txtAddress.Text;
}