Which validator control you use if you need to make sure the values in two different controls matched?

Compare Validator control.

In ASP.NET, if you need to ensure that the values in two different controls match, you can use the CompareValidator control.

The CompareValidator control compares the value entered into an input control with the value entered into another control or a constant value. You can specify the type of comparison operation (such as equality, less than, greater than, etc.) and the control to compare against using the ControlToCompare property.

Here’s a basic example of how you might use the CompareValidator control to ensure that two password fields match:

html
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:TextBox ID="txtConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="txtConfirmPassword" ControlToCompare="txtPassword" ErrorMessage="Passwords must match"></asp:CompareValidator>

In this example, the CompareValidator is associated with the txtConfirmPassword control and compares its value with the txtPassword control. If the values do not match, the error message “Passwords must match” will be displayed.