Use of ASP. NET verification controls

Source: Internet
Author: User

I think that after several years of Web development, I knew Asp.net very well, but I finally found that this was not the case. First, there is no systematic learning, and secondly, there is no in-depth practice. from school to company, we have been using controls written by others. Even for a long time, we want to write a few wheels. After self-deprecating your own things, I began to learn about these things slowly. I learned about the verification control a few days ago and recorded it. I hope it will be comfortable when I forget it later.

Microsoft provides six verification controls, namely, five verification controls and one centralized display control. Among these controls, the simplest is the RequiredFieldValidator control, which is required for verification. When the verified control does not input data, the verification fails and cannot be executed. This control is verified on the client and server segments respectively. The second is the RegularExpressionValidator control. This control requires a regular expression. The ValidationExpression attribute is the verified regular expression, this control also performs simultaneous server and client verification, unless the client does not support js, or it is shown that only server verification can be performed to prevent client verification.

Another verification control is the CustomValidator control, which can only be verified on the server side. The verification method is flexible. When verification is triggered, a server method is executed, this method must be specified in OnServerValidate and verified in the background code. In this code, it must be args. isValid value assignment, true or false. The verification is successful or fails. This is simple.

The other two are the CompareValidator control and the RangeValidator control. The first one is used for comparison. You can compare the value of the input control with the constant value or the value of other input controls, to determine whether these two values match the relationship specified by the comparison operator (less than, equal to, greater than, and so on. The second is used to calculate the input data and verify whether it is within the specified range.

 

Finally, all controls have a ControlToValidate attribute, specifying the control to be verified, the ValidationGroup attribute, and specifying a verification group where verification is required, such as Button, also set this property to the same. This completes the verification.

 

As for the ValidationSummary control, verification information is displayed together. I hope that you will not forget it in a few years.

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.