Sunday, January 25, 2009

Validation controls

Validation controls contain 5 controls that make comparisons and 1 control that summarizes any errors that appear. All validation controls need to be placed within a Form or a Panel control, or inside a control's template on a mobile Web page. A validation control can be dragged onto a mobile user control page.

  • RequiredFieldValidator : Used to validate user entered data into a SelectionList or TextBox control. With a SelectionList control, the user needs to select an item in the list. With a TextBox control, the user needs to enter a value.
  • CompareValidator: Used to compare the data value entered by the user to a value in another control. Set the ControlToCompare property to the string in the id property of the SelectionList or TextBox control that contains the comparison value and the ValueToCompare property to the comparison value .
  • RangeValidator : Used to validate whether user input falls within a specified range. Use the MinimumValue and MaximumValue properties.
  • RegularExpressionValidator : to test whether the user input in a TextBox or SelectionList control matches a regular expression. The regular expression pattern is specified in its ValidationExpression property. You can specify regular expressions or select from a list of predefined expressions.
  • CustomValidator : Use this to create a control that performs customized validation. It also validates input from the TextBox or SelectionList control. Set its ControlToValidate property to the ID of the control, to validate. When a form that contains a CustomValidator control is posted to the server, the CustomValidator control raises a ServerValidate event. In this event, you can write the custom validation code you want. Eventually, you can set the IsValid property of the validation eventArgs to true or false, depending on the outcome of the validation.
  • ValidationSummary: Use to to present the user with a list of validation errors that occurred when a form was posted on the server. The mobile version of the ValidationSummary control displays a back-link for the user to return to the form and correct the data entered.

Each validation control can display an error message at the position of the validation control on the form. Validation errors can be collected in a validation summary control and can be displayed at a single place, such as at the top of the page.

Set the Display property to None, Static , or Dynamic , to check whether the validation control displays error messages. You can select Dynamic to display the results of the validation, and None, if you do not want to display the results. In the current version of the ASP.NET mobile controls, Dynamic and Static have similar meaning.

You can use the mobile version of the ValidationSummary control to display a list of validation errors that occurred when a form was submitted. This control lists all the error messages generated by the other validation controls on the form. The ValidationSummary control obtains the error message strings from the ErrorMessage properties of the validation controls.

No comments:

 
Google