User-650628323 posted
Hi dgupta.sw,
I am sorry I can't reproduce your issue locally. To resolve your issue, please make sure the event handler has correct parameter types firstly. Then, please test the code below and see whether it works locally.
In the .aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="Form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="name:" />
<asp:TextBox ID="txt1" runat="server" />
<asp:Button ID="Button1" Text="Submit" runat="server" onclick="Button1_Click" />
<br />
<asp:Label ID="mess" runat="server" />
<br />
<asp:CustomValidator ID="CustomValidator1" ControlToValidate="txt1" OnServerValidate="CustomValidator_ServerValidate"
Text="wrong!" runat="server" />
</form>
</body>
</html>
In the .cs
public void CustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
if (args.Value.Length < 8 | args.Value.Length > 16)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}
If it works well, please compare it with your code and try to find the issue. If it doesn't work, please provide more information about your code. That will help us to continue. Thank you for your support.