- CompareValidator control is used to compare/match the value of one input control to the value of another input control.
- Mostly this control is used to Entering the Password detail in Registration form.
- For this control we must specify the input Datatype for comparison.
-
Input Type may be:– String– Date– Currency– Integer– Double
- Here we have to set two property for validation.
- ControlToValidate – The main input control means Original first password.
- ControlToComapre – The second input control which is compare with main control, means confim -password control.
<table align="center" class="style1" style="border: thin solid #008080"> <tr> <td colspan="2" style="border-bottom: thin solid #008080; font-weight: 700; text-align: center; color: #990033;" class="style2"> CompareValidator Control in ASP.Net</td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td style="font-weight: 700; text-align: right"> Name :</td> <td> <asp:TextBox ID="txtname" runat="server"></asp:TextBox> </td> </tr> <tr> <td style="font-weight: 700; text-align: right"> Password :</td> <td> <asp:TextBox ID="txtpassword" runat="server"></asp:TextBox> </td> </tr> <tr> <td style="font-weight: 700; text-align: right"> Confirm - Pass :</td> <td> <asp:TextBox ID="txtconfipass" runat="server"></asp:TextBox> <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txtpassword" ControlToValidate="txtconfipass" ErrorMessage="Password not same !!"></asp:CompareValidator> </td> </tr> <tr> <td> </td> <td> <asp:Button ID="Button1" runat="server" Font-Bold="True" Text="SAVE" /> </td> </tr> </table>

