CompareValidator compares the value of one form field against another form field. : CompareValidator « Validation « ASP.NET Tutorial






<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Show Compare Values</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <asp:Label
        id="lblStartDate"
        Text="Start Date:"
        Runat="server" />
    <asp:TextBox
        id="txtStartDate"
        Runat="server" />
    <br /><br />

    <asp:Label
        id="lblEndDate"
        Text="End Date:"
        Runat="server" />
    <asp:TextBox
        id="txtEndDate"
        Runat="server" />
    <asp:CompareValidator
        id="cmpDate"
        Text="(End date must be greater than start date)"
        ControlToValidate="txtEndDate"
        ControlToCompare="txtStartDate"
        Type="Date"
        Operator="GreaterThan"
        Runat="server" />
    <asp:Button
        id="btnSubmit"
        Text="Submit"
        Runat="server" />
    </div>
    </form>
</body>
</html>








8.2.CompareValidator
8.2.1.CompareValidator performs three different types of validations
8.2.2.CompareValidator performs a comparison against a fixed value.
8.2.3.CompareValidator compares the value of one form field against another form field.
8.2.4.asp:CompareValidator, Type='String', Operator='NotEqual' and ErrorMessage
8.2.5.What happens to asp:CompareValidator in the client side
8.2.6.Set DeleteParameters, InsertParameters and UpdateParameters for asp:SqlDataSource
8.2.7.Using the CompareValidator to test values against other control values
8.2.8.Using the CompareValidator to validate against constants
8.2.9.To specify the data types: Currency, Date, Double, Integer, String
8.2.10.Making comparisons with the CompareValidator control
8.2.11.CompareValidator for number, text and password
8.2.12.Disable Client Validation
8.2.13.Use CompareValidator to check password field and confirm password field
8.2.14.CompareValidator with age field
8.2.15.Check birthday