CompareValidator control example

CompareValidator control example

Previous Home Next

 

The CompareValidator control compares the value of one control to another, or to an explicit value in the control's ValueToCompare property. CompareValidator uses three key properties to perform its validation. ControlToValidate and ControlToCompare contain the values to compare. Operator defines the type of comparison to perform, for example, Equal, Not Equal, Greater than, Less than, DataType and others. CompareValidator performs the validation by evaluating these properties as an expression.
When the type of value being compared is not a string, you have to specify the Type property as one of the following:

String 
Integer 
Double 
Date 
Currency 

  
   

The CompareValidator has six important properties:

ControlToValidate— The ID of the form field being validated. 
Text— The error message displayed when validation fails. 
Type— The type of value being compared. Possible values are String, Integer, Double, Date, and Currency. 
Operator— The type of comparison to perform. Possible values are DataTypeCheck, Equal, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual, and NotEqual. 
ValueToCompare— The fixed value against which to compare. 
ControlToCompare— The ID of a control against which to compare. 

 ................design code........................................
....................................................................
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>





    Untitled Page


    
             

          Password Not match


                
........................................................................................................................................ ..................................cs code........................... .................................................................... using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Response.Write("U have Entered correct password"); } } .....................................................................
Previous Home Next