- This Validation Control is used to perform both client side & Server side validations when existing validation Controls do not meet the user requirement then use custom Validator.
- This is the only Control that can be used to perform both Client Side and Server Side Validations.
1) ControlToValidate
2) ErrorMessage
3) Text
4) ValidationGroup
5) ClientValidationFunction
6) ValidateEmptyText(options:[True/False])
5) ClientValidationFunction:-This property is used to set the required JavaScript Function using which we want to perform client side validations.
6)ValidateEmptyText:-When set to true CustomValidator will check whether user entered data or not within the Control to validate .When set to False CustomValidator will not check whether user entered Data or Not.
Example with Custom Validator:-
Validations to be performed:-
Check whether Password is Maximum “6” Characters or not .
Create a new webpage
Design the webpage
Set the following properties for CustomValidator1:-
ID --- CV1
ControlToValidate --- txtPassword
ClientValidationFunction --- F1
Text --- Password should be minimum six characters
Go to source & Write the following code for Function F1 in JavaScript like:-
</head>
<script type="text/javascript">
function
F1(a, b) {
if
(b.Value.length < 6)
b.IsValid = false
else
b.IsValid = true
}
</script>
<body>
|
Run the Application and check.
Function Description:-
- Any Function we call from CustomValidator ClientValidationFunction must and should have two arguments with Any Name.
- In the above Example we have taken two arguments “a, b” for F1 ( ).
- In these two arguments First argument will return the Control from which Function has been called.
- Second Argument has two properties
2) IsValue
Value property will return the data entered by user in the Control that we are validating.
IsValid is a Boolean property after Execution of Function this property value will return to CustomValidator & CustomValidator will return to the Webpage.
No comments:
Post a Comment