ASP. NET to verify the use of controls, asp.net Control

Source: Internet
Author: User

ASP. NET to verify the use of controls, asp.net Control

For the validation of these commonly used controls, there are separate validation controls available in Asp. Net. They can perform common verification, such as non-empty verification, range verification, and comparison, and add the input data verification and verification code functions to the user logon page.

Verification control:

The Built-in validation controls in Asp. Net include RequiredFieldValidation, RangeValidation, RegularExpressValidation, CompareValidation, CustomValidation, and ValidationSummary. The user-defined verification control is not discussed here because it is not very common (many components, including functions, need to be customized.

The simple verification interface is as follows (Design view ):

 

The error message of the verification control is displayed in red on the right of the selected environment. The design environment layout is as follows:

1) The ControlToValidate attribute of the RequiredFieldValidation control is the text box corresponding to the name. For the ControlToValidate attribute, each verification control corresponds to one and serves as the verification subject;

2) RangeValidation control, whose ControlToValidate attribute is the age text box;

3) The ControlToValidate attribute of the CompareValidation control is the text box corresponding to Password confirmation. There is also an attribute that is easy to confuse with the ControlToValidate attribute: ControlToCompare attribute, which corresponds to the text box of the password. Differentiation: the key point is to distinguish the subject. In this case, the verification subject is the Password confirmation box. When operator is used (equal to, greater than, less than), it is the comparison subject, compared with the text box to be compared, This is the text box corresponding to the password.

4) The RegularExpressValidation control, whose ControlToValidate attribute is the text box corresponding to the mailbox;

5) ValidationSummary control, which does not have the ControlToValidate attribute;

The corresponding front-end code is:

<Head runat = "server"> <title> verification control demo page </title> <script type = "text/javascript"> // Notes: use an example to simulate a user table </script> 

When the input in the text box does not match, the following page appears:

 

Appendix:

For all RequiredFieldValidation controls, when they are only for the Name box, when other boxes are empty, their corresponding verification controls are invalid. It can be considered that except the RequiredFieldValidation control, other controls can only function on the basis of this control.

The above is all the content in this article. I hope it will be helpful for you to use the validation controls in ASP. NET.

Related Article

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.