ASP.NET : Custom Validator

Custom Validator
Checks the user's entry using validation logic that you write yourself. This type of validation enables you to check for values derived at run time.

Properties

ClientValidationFunction: Which JavaScript function that you want to check.

Example

1. Create a ASP.NET website then add Standard TextBox and CustomValidator.
2. Create your JavaScript Function for validate (For this example will check about input digits).

        <! Example !!>
        <head> <title>Test Validate</title>

        <script language="JavaScript">
           function checkDigit(source, agrs) {
               if(agrs.Value.length < 8 || agrs.Value.length > 12
                   args.IsValid = false;
               else
                   args.IsValid = true;
           }
        </script></head> 

3. Select your CustomValidator and set require properties for validate (see Table 1).



PropertiesValue
ClientValidationFunctioncheckDigit
ControlToValidateTextBox1
ErrorMassagePlease input 8-12 characters

Table 1: Require Properties for CustomValidator

4. Test your application you will see error message when you input wrong condition (Figure 1).


Figure 1: Custom Check  Example

##############################

CompareValidator (Check Data Type) << Previous Chapter || Next Chapter >> RangeValidator

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...