Do not let comparevalidator display error before clicking button

I have a password text box and confirm the password text box in which I use comparevalidator to make sure they are equal. If this is not the case, I want the user to receive an error message stating that they do not match. However, I do not want this to be displayed until the user clicks a button. What is currently happening is that when I switch from the first text field to the second, I immediately get this error.

How can I prevent this error from appearing until I press a button?

+6
source share
1 answer

A very easy way to get around this would be to reverse ControlToCompare and ControlToValidate

 <label>Password: <asp:TextBox ID="password" runat="server"></asp:TextBox></label><br/> <label>Confirm Password:<asp:TextBox ID="confirmPassword" runat="server"></asp:TextBox></label> <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="password" ControlToValidate="confirmPassword" ErrorMessage="Passwords do not match"></asp:CompareValidator> 

Having canceled these properties, the check should happen only when they leave the password confirmation text field. (This assumes that the user fills out the form from top to bottom, and not from bottom to top, but who does it anyway)

+4
source

Source: https://habr.com/ru/post/905123/


All Articles