asp.net customvalidator tips
Posted on 2011-04-19
A Custom Validator can be quite tricky to get right.
Here are some tips that were used in a hairy validation.
For starters, lets assume that there is a checkbox and textbox that work together in validation.
1. Add a textbox which is non-empty to act as the ControlToValidate in the CustomValidator.
Set style="display:none" so it doesn't display.
Other code will be looking for it, and gripe if it is null.
2. Assign the ErrorMessage in the CustomValidator.
You can't set it an client run time.
3. Provide OnServerValidate function in code-behind.
4. Add ClientValidationFunction
Set args.IsValid = true or false
No response needed.