Comparevalidator for ASP. NET verification controls

Source: Internet
Author: User

You should be familiar with comparevalidator. It is used to compare the values entered in the two input boxes. The most common one is to check whether the passwords entered twice are consistent during user registration. I believe that anyone on the Internet has ever met me! Let's take a look at his common attributes:



Attribute


Description


Backcolor


Background color.


Controltocompare


The input control to be compared with the verified input control.


Controltovalidate


ID of the input control to be verified.


Display


verify the display behavior of error messages in the control.


valid values:


· The none verification message is never displayed inline.


· static: Allocate space for displaying verification messages in the page layout.


· if the verification fails, dynamic dynamically adds the space used to display the verification message to the page.


Enableclientscript


Boolean value that specifies whether to enable client verification. True indicates enabled, and false indicates disabled.


Enabled


Boolean value that specifies whether to enable the verification control. True indicates enabled, and false indicates disabled.


Errormessage


Text displayed in the validationsummary control when verification fails.


Note: If the text property is not set, the text is displayed in the verification control.


Forecolor


The foreground color of the widget. That is, the font color of the error message.


ID


The unique ID of the control.


Isvalid


Boolean value indicating whether the input control specified by controltovalidate has passed verification. True indicates pass, and false indicates fail.


Operator


The type of the compare operation to be executed.


OPERATOR:


· Equal equals


· Greaterthan is greater


· Greaterthanequal greater than or equal


· Lessthan is smaller


· Lessthanequal is less than or equal


· Notequal is not equal


· Datatypecheck verifies the data type (if the specified type is integer, the input character cannot pass verification)


Runat


The specified control is a server control. Must be set to "server ".


Text


Message displayed when verification fails.


Type


Specifies the Data Type of the value to be compared.


Types:


· Currency


· Date


· Double


· Integer


· String


Valuetocompare


A constant value, which must be compared with the value entered by the user to the verified input control.





The following is the actual application of comparevalidator:

 

 

 <% @ Page Language  =  "  C #  "  Autoeventwireup  =  "  True  "  Codebehind  = "  Password comparison. aspx. CS  "  Inherits  =  "  Webapplication1. password comparison  "   %>  <!  Doctype html  >  < Html  Xmlns  = "Http://www.w3.org/1999/xhtml"  >  <  Head  ID  = "Head1"  Runat  = "Server"  >      <  Meta  HTTP-equiv  = "Content-Type"  Content = "Text/html; charsets = UTF-8"   />      <  Title  > Password comparison </  Title  >  </  Head  >  <  Body  >      <  Form  ID = "Form1"  Runat  = "Server"  >          <  ASP: Label  ID  = "Lbpwd1"  Runat  = "Server"  Text  = "Enter the password :"  > </  ASP: Label  >          <  ASP: textbox ID  = "Txtpwd1"  Runat  = "Server"  Textmode  = "Password"  > </  ASP: textbox  >          <  BR  />          <  BR  />          <  ASP: Label ID  = "Lbpwd2"  Runat  = "Server"  Text  = "Confirm Password :"  > </  ASP: Label  >          <  ASP: textbox  ID  = "Txtpwd2"  Runat  = "Server"  Textmode  = "Password" > </  ASP: textbox  >          <  ASP: comparevalidator  ID  = "Comparevalidator1"  Forecolor  = "Red"  Runat  = "Server"  Errormessage  = "The two passwords are inconsistent"  Controltovalidate  = "Txtpwd1"  Controltocompare = "Txtpwd2"  > </  ASP: comparevalidator  >          <  BR  />          <  BR  />          <  ASP: button  ID  = "Btnsubmit"  Runat  = "Server"  Text = "Submit"   />      </  Form  >  </  Body  >  </  Html  > 

 

When the two passwords are inconsistent, the following prompt is displayed (of course, the prompt message is defined by yourself ):



Note that if you enterAllSpace. If no value is entered, the two numbers are the same because comparevalidator treats all the spaces as nothing. However, if the actual content is entered, no matter where the space is added, an error will be reported if the content of the two boxes is different. Comparevalidator does not remove spaces at the beginning and end by default. Note This.

 


Although comparevalidator differs from Js in terms of resource consumption and user experience, it is easy to use and is suitable for beginners. I will introduce the js method later.

 

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.