The below code is works using document.write. How to display the value exceeded in Label1 and also how to change the background color of TextBox to red (Using JavaScripts) if value exceeded.
<script type="text/javascript">
function limitlength(obj, length) {
var maxlength = length
if (obj.value.length > maxlength)
document.write("Exceeded") }
</script>
Enter text (max length is 5 characters):
<form id="form1" runat="server">
<asp:textbox ID="TextBox1" onkeypress="return limitlength(this, 5)" runat="server"></asp:textbox>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>