Wednesday 26 June 2013

Server Control Validation Controls Work

Briefly explain how the server control validation controls work?

A validation control works by evaluating the value of an input server control on the page to see whether it meets certain criteria. The input control to evaluate is specified through the validation controls Control To Validate attribute. You can programmatically cause a validation control to perform its evaluation by calling its Validate method, which sets the validation controlls IsValid property to true if validation succeeds and false if it fails. You can cause all of the validation controls on a page to validate their input controls by calling the Page.Validate method.

The Page Is Valid property is set to true if validation succeeds for all validation controls within the page; otherwise, it's false. The Page.Validate method is automatically invoked when a button control whose CausesValidation property is set to true is clicked. Causes Validation is set to false by default for a reset or clear button. The button click event is suppressed if IsValid is false for any validation control on the page.



There are following types of validation controls provided by ASP.Net:
1. Required Field Validator
2. Compare Validator
3. Range Validator
4. Regular Expression Validator
5. Custom Validator

These controls are server side controls. However in up-level browsers that is IE 4.0 and above these can be enabled on client side also.

All these controls have a property called Control To Validate. Required Field Validator ensures
data entry into the Control To Validate.

Compare Validator uses Control To Validate, Control To Compare and operator properties to compare a control's value with another control's value. It also has a property 'Value To Compare' for comparing Control To Validate against a constant value.

Range Validator uses Control To Validate, Maximum Value and Minimum Value to compare a controls value against a range.

Regular Expression Validator uses Control To Validate and Validation Expression properties. Custom Validator performs its task by using Client Validation Function and OnServer Validate delegate.


EmoticonEmoticon