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

 Posted by ArticlesMaint on 9/16/2009 | Category: ASP.NET Interview questions | Views: 3356


Answer: -
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" /><br>
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;
}
}
// -->
</script>


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response