Asp. NET validation controls

Source: Internet
Author: User

in the course of the room charge system when. In order to verify that the text box is empty, the user exists, is legal, and so on. We all have to write the code separately. Learning the validation Controls for ASP.

ASP Enables easy validation of user input.

Let's think about The six types of validation controls that are common to ASP.


1 , basic validation controls:

(1) RequiredFieldValidator: Limit empty fields (mandatory field validation) to check for input values


Example: When landing. You need to verify that the input username and password are empty

<asp:requiredfieldvalidator id= "RequiredFieldValidator1" runat= "Server" controltovalidate= "txtUserName" Errormessage= "username must be entered" ></asp:RequiredFieldValidator>

(2) Basic Comparative Control

a , CompareValidator: Compare two fields comparison verification) two inputs per set


Example: When we change password. The first input password and the second input is consistent, can use this control.

<asp:comparevalidator id= "CompareValidator1" runat= "Server" controltocompare= "TxtPassword1" controltovalidate= " TxtPassword2 "errormessage=" two times password inconsistent "></asp:CompareValidator>


b , RangeValidator: checks whether the specified range (range validation) input is in the specified range


For example: the size of the input information range

    
   

For example: the size of the input information range

(3) RegularExpressionValidator: use a regular table to check the value (normal form validation) the normal table validation control


    
   

(4) CustomValidator: Check values (self-defined validation) by client or server function to define validation controls yourself

   

3 , validation summary control

(1) ValidationSummary: list validation errors for all controls in the page (validation Summary) Summary validation Results


Example: summary of all validation information

   
     <span style= "font-family:kaiti_gb2312; Background-color:rgb (255, 255, 255); " > </span>
   

Page.IsValid Properties:

<scrip language= "C #" runat= "Server" >void subbtn (Object src,eventarge E) {if (page.isvalid==true) <span style= " White-space:pre "></span>{lblmessage.text=" page valid ";}} </script>
Page: The current entire page, no matter what one does not pass the value to verify it is false.

To summarize:

Each validation control runs a specific type of validation and presents its own custom SMS prompt when validation fails. Validation control Our development provides a very great help, we do not need too much code, you can verify various certifications.


Asp. NET validation controls

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.