In Webform1.aspx
<SCRIPT language="c#" runat=server >
void validateLength(object source, ServerValidateEventArgs args){
int num = int.Parse(args.Value.Length.ToString());
if (num >= 4000)
{
args.IsValid=false;
}
else
{
args.IsValid=true;
}
}
</SCRIPT>
<asp:TextBox
id="TextBox1"
style="Z-INDEX: 102; LEFT: 192px;
POSITION: absolute; TOP: 311px"
runat="server"
TextMode="MultiLine">
</asp:TextBox>
<asp:CustomValidator
id="CustomValidator1"
runat="server"
ControlToValidate="TextBox1"
OnServerValidate="validateLength">
</asp:CustomValidator>
And in webform1.aspx.cs
private void Button1 Click(object sender, System.EventArgs e)
{
if (Page.IsValid)
{
Response.Write ( "Length Proper =4000");
}
}