You find that one of your validation is very complicated and does not fit in any of the validators, what will you do

Q

You find that one of your validation is very complicated and does not fit in any of the validators, what will you do ?

✍: Guest

A

Best is to go for CustomValidators. Below is a sample code for a custom validator which checks that a textbox should not have zero value


<asp:CustomValidator id="CustomValidator1" runat="server"
ErrorMessage="Number not divisible by Zero"
ControlToValidate="txtNumber"
OnServerValidate="ServerValidate"
ClientValidationFunction="CheckZero" />
Input: <asp:TextBox id="txtNumber" runat="server" /> <script language="javascript"> <!-- function CheckZero(source, args) { int val = parseInt(args.Value, 10); if (value==0) { args.IsValid = false; } else { args.IsValid = true; } } // --> </script>

2007-10-24, 4635👍, 0💬