Summary of asp.net verification controls

Source: Internet
Author: User
Verification control Overview

Verification controls include: RequiredFieldValidator (required), RangeValidator (range), RegularExpressionValidator (Regular Expression), CompareValidator (comparison and type), CustomValidator (custom), ValidationSummary (Information prompt summary), a total of six verification controls.


Function Description of the verification control: RequiredFieldValidator-make sure that the required value CompareValidator-verifies a value based on the value or constant of another control, or make sure that the input value is of a specific type RangeValidator-make sure that the input value is within a certain range RegularExpressionValidator-according to the regular expression (regular expression) to verify a value of mmvalidator-verify a value of ValidationSummary based on the user-defined method-on the page, all the prompts of the preceding five verification controls are displayed in summary or in group summary.

Verify the basic properties of the control:

ControlToValidate: Set the control to be verified, which must be set; otherwise, compilation fails. ValidationSummary does not have this attribute.

Text property: This property exists in addition to the ValidationSummary control. The function is to display the information on the control. If this attribute is not set, the display information on the control will be replaced by the value set by the ErrorMessage attribute. If the Text value is set, the verification control displays the Text value (when prompted), regardless of whether the ErrorMessage attribute value is set, unless the encoding changes.

ErrorMessage property: This property exists except the ValidationSummary control. This property value will be displayed when the verified control exceeds the condition, but when the verification control sets the Text property, the property value of ErrorMessage cannot be displayed on the verification control (in this case, the control displays the Text value), unless the verification control and the summary control ValidationSummary are used in combination, the ErrorMessage property value is displayed on the ValidationSummary control.

ValidationGroup property: This property serves to associate the verification control with the verified control group. The summary control only displays the verification prompt information in the group (Verification Failed ). This will not affect the verification or use of other controls. Verify that all controls and other controls have this property. Such as ButtonBox and TextBox. The setting of this attribute generally occurs on the page where multiple summary controls ValidationSummary exist.

SetFocusOnError attribute: When set to true, RequiredFieldValidator can automatically locate the control with an error.

Display attribute: Set to Dynamic to dynamically occupy space.


Summary control ValidationSummary:This control does not have the Text and ErrorMessage attributes. The ValidationGroup attribute is often used on the pages of ValidationSummary of multiple summary controls to avoid affecting the verification and use of other controls. The summary control ValidationSummary can display the prompt information in two ways. One is to display the prompt information in text format at the position of the summary control ValidationSummary (set the ShowSummay attribute to true ), the other method is to use the pop-up MessageBox method (set ShowMessageBox to True). You can also use two methods to display the prompt information.

Note:

1. When the Page is postback, all the verification controls perform verification and then submit the verification report to Page. IsValid. The verification effect of some verification controls (the verification prompt is displayed) can be displayed when the TextChanged event (the Text value in the TextBox changes and cannot be confused with the focus event) occurs, such as RequiredFieldValidator.

2. By default, the verification control generates JavaScript and performs verification on the client. When you click Button, LinkButton, or ImageButton, the verification control will check before the page postback. If the data is invalid, postback does not occur. However, for some buttons, data does not need to be verified. In this case, it is very annoying to cancel postback. This is the case with Cancel button. Imagine that the user has entered invalid data, such as ignoring the product name, and then deciding that the user does not need to save the product, and then clicks the Cancel button. In this case, the Cancel button triggers the verification control, which reports that the product name is missing and prevents postback. You have to enter the information in the Product TextBox as required before canceling the editing. Fortunately, the Button, LinkButton, and ImageButton have CausesValidation property, which indicates whether verification is required when you click the Button (True by default ). Generally

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.