This Control is used to compare the value or one control to the value of another control or to a fixed value. One catch here is that validation pass if both the fields are empty. To handle that one require to apply Required field validator along with CompareValidator.
<asp:TextBox ID="TextBox1" runat="server" /> <asp:TextBox ID="TextBox2" runat="server" /> <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="TextBox2" Display="Dynamic" ValidationGroup="MyGroup" ToolTip=" password not matched No Match" ControlToCompare="TextBox1" > * password not matche pls reenter password</asp:CompareValidator>
This take the Id of control with which comparison is being done.
Comparison can be made on following data types:
Currency, Date, Double, Integer and String
|ControlToCompare||Specifies the name of the control which acts like a source control.|
|Type||Specifies the data type to be used for validating the input. Default type is ‘string’.|
|Operator||Specifies the operator to be used for validating the user input. Default is ‘Equal’.|
In order to group the validation controls together ‘ValidationGroup’ property for all the controls which belongs to the group should be set with the same name
if password are same