I have a password textbox and confirm password textbox in which I use a comparevalidator
to make sure that they are equal. If they aren't, I want the user to receive an error message that says they don't match. However, I don't want this to display until the user clicks a button. What is currently happening is that when I tab from the first textbox to the second, I immediately receive that error.
How can I prevent this error from showing up until after I click a button?
A very simple way to get around this would be to reverse the ControlToCompare
and the 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>
By reversing these properties the validation should only occur when they tab off the confirm password text box. (This assumes the user fills out the form top down and not bottom up, but who does that anyways)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With