Tuesday, February 2, 2010

ASP.NET validation control

Define Validation Control in ASP.NET.

 The validation control is used to implement page level validity of data entered in the server controls. This check is done before the page is posted back to the server thus avoid round trip to the server. If data does not pass validation, it will display an error message to the user.   

What are the validation types supported by ASP.NET?

  Following are the validation types in ASP.NET:
  • The RequiredFieldValidator control forces the input control a required field.
  • The CompareValidator control is used to compare values of the two input fields.
  • The CustomValidator control allows you to write a method to handle the validation of the value entered.
  • The RangeValidator control is used to check that the user enters an input value that falls between two values. It is possible to check ranges within numbers, dates, and characters.
  • The RegularExpressionValidator control ensures an input value matches a specified pattern.
  • The ValidationSummary control is used to display a summary of all validation errors occurred in a Web page.

Describe the steps to use Validation Control.

  • Draw a validation control on a Web form
  • Set the ControlToValidate property to the control you want to validate.
  • Specify the ControlToCompare property with CompareValidator control.
  • Specify error message to the validation control’s ErrorMessage property.
  • Specify error message to the validation control’s Text property if you want to display a message other than the message in the ErrorMessage property.
  • Draw a ValidationSummary control on the Web form to display the error messages from the validation controls in one place.

0 Comments: