CustomValidator control is used to validate an input control with user-defined function either from server side or client side.
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator">
</asp:CustomValidator>
Properties:
ClientValidationFunction | Specifies the name of the client-side validation script function to be executed. |
ControlToValidate | The id of the control to validate |
Error Message | The text to display in page when validation fails. Note: This text will also be displayed in the validation control if the Text property is not set |
OnServerValidate | Specifies the name of the server-side validation script function to be executed |
<script type="text/javascript">
function validatenumber(oSrc,args)
{
args.IsValid = (args.Value % 2 == 0)
}
</script>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="enter only even number"
ClientValidationFunction="validatenumber">
</asp:CustomValidator>
Validatenumber function is used to check that enter number is even or odd.It accepts only even nomber
When you will enter odd number then error message will show.
When we enter even number then page will execute
Leave Comment