Controls (6) -- verify controls

Source: Internet
Author: User

Verification controls are important for us. Although it is not advanced, it is often used.

Knowledge about the application of the verification control:

1. The appearance can be defined;

2. The display method of the verification program can be static or dynamic;

3. An error message is displayed in the group;

4. Custom server Verification;

5. Custom client verification;

6. Regular Expression.

 

Let's take a look at an example of registration information. I will not introduce it too much here. I will give you an interface to see it at a Glance:

 

 

 

Requiredfieldvalidator control: used to enter the user name, password, and password. For the user name, the most important thing is to set the controltovalidate attribute of the verification control to the ID of the corresponding text box. Others are similar.

 

Comparevalidator control: determines whether the two passwords are the same. It is important to set the controltocopmare attribute and controlvalidate attribute of the control to the ID of the text box to be verified. You can explore other functions by yourself.

 

Regularexpressionvalidator control: used to determine whether the email address is entered correctly. In the controltovalidate attribute, enter the ID of the control to be verified (for example), and then select the appropriate type in the validationexpression (Regular Expression used to determine the validity) attribute, it automatically generates Regular Expressions (for specific regular expressions, see the blog post ).

 

Rangevalidator control: Verify that the range of input numbers meets the requirements. Enter the ID of the verification text box in the controltovalidate property, and enter 200 in the maximumvalue property (maximum value of the verified control) and 100 in the minimumvalue property (minimum value of the verified control.

 

Validationsummary control: the control is like a summary. After submission, all errors are summarized.

Customvalidator control: Implements custom verification for servers and clients. Similarly, you must enter the ID of the text box to be verified in the controltovalidate attribute.

 

Background code:

Public partial class kongjian4: system. web. UI. page {/// <summary> /// verify the control /// 1. It can display the defined appearance /// 2. The display mode of the verification program, static or dynamic (note the two types of the first verification control) /// 3. The group displays the error message /// 4. Customize server verification /// 5. Customize client verification /// 6. Regular Expression /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> protected void page_load (Object sender, eventargs e) {} protected void txtvalue (Object source, servervalidateeventargs ARGs) {args. is Valid = (ARGs. value = "server");} protected void button#click (Object sender, eventargs e) {If (isvalid) {label1.text = "congratulations, all pass! ";}Else {label1.text =" Haha, an error occurred ";}}}

Here, we use a script:

 

<Head runat = "server"> <title> No title page </title> <SCRIPT type = "text/JScript"> function clientv (S, e) {If (E. value = "client") {e. isvalid = true;} else {e. isvalid = false ;}}</SCRIPT> 

 

Click submit directly to demonstrate the effect:

 

Try the effects of other controls by yourself.

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.