ASP.NET CompareValidator

In this post we will see how to use compare validator to compare the two input values. Using compare validator we can compare two values from two different input controls or we can compare input value with some constant or fixed value.

Example of compare validator

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <ul style="list-style-type: none">
                <asp:TextBox ID="txt1" runat="server" />
                <asp:TextBox ID="txt2" runat="server" />
                <asp:Button ID="Button1" Text="Validate" runat="server" />
        <asp:CompareValidator ID="compareval" Display="dynamic" ControlToValidate="txt1"
            ControlToCompare="txt2" ForeColor="red" Type="String" EnableClientScript="false"
            Text="Values are not equal." runat="server" />

So in compare validator we need to set ControlToValidate and ControlToCompare in order to compare two input values.


Post a Comment