Example for Custom validator
In Designer aspx
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
<asp:CustomValidator ID=”CustomValidator1″ runat=”server”
ErrorMessage=”Not a even no” ControlToValidate=”TextBox1″
ForeColor =”Red” onservervalidate=”CustomValidator1_ServerValidate”
></asp:CustomValidator>
<asp:Button ID=”Button1″ runat=”server” Text=”Button” />
In aspx.cs
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (Convert.ToInt32(args.Value) % 2 == 0)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}