Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent comparevalidator from displaying error until button is clicked

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?

like image 388
The Vanilla Thrilla Avatar asked Jan 04 '12 18:01

The Vanilla Thrilla


1 Answers

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)

like image 64
Mark Coleman Avatar answered Oct 09 '22 10:10

Mark Coleman