We help IT Professionals succeed at work.

Compare Validator Reacts Before Sumit is Clicked

net_susan
net_susan asked
on
Medium Priority
475 Views
Last Modified: 2011-09-20
This compare validator reacts as soon as a user types in the password, not even giving time to type in the password confirmation. How can I make it so this validator only reacts after submit is clicked?

<asp:comparevalidator id="comparepw" Runat="server" ControlToValidate="password" controlToCompare="confirmpw">
Password and confirm password do not match!</asp:comparevalidator>
Comment
Watch Question

Commented:
are you using a validation summary? generally, validator controls have an errormessage property set that sends an error message to a validation summary which should run at submit.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Commented:
<asp:comparevalidator id="comparepw" Runat="server" ControlToValidate="password" controlToCompare="confirmpw" EnableClientScript = "true">
Password and confirm password do not match!</asp:comparevalidator>

This will cause the validator to only fire when the submit button is clicked. Alternatively you can set the ControlToValidate and the ControlToCompare to be opposite:

ControlToValidate="confirmpw" controlToCompare="password"

Both of those should work for you. The Second will reduce the number of server requests.
Commented:
Add  EnableClientScript="False"

so it looks like this:
<asp:comparevalidator id="comparepw" Runat="server" ControlToValidate="password" controlToCompare="confirmpw" EnableClientScript="False">

Author

Commented:
I did this:

This will cause the validator to only fire when the submit button is clicked. Alternatively you can set the ControlToValidate and the ControlToCompare to be opposite:

ControlToValidate="confirmpw" controlToCompare="password"

Author

Commented:
Thanks everyone!

Commented:
Sorry, mixed up those stupid bool validators, but still, switching the controltocompare and the controltovalidate is a more efficient way because you don't have to wait for a postback event.

Author

Commented:
If you see this, please explain what this means:

Sorry, mixed up those stupid bool validators,


I'm just a .NET baby.  :)

Commented:
in my original post i said to use: EnableClientScript = "true"

then aki4u corrected me by saying: EnableClientScript="False"

I was copying code i previously used in which i wanted to force client scripting and forgot to change "true", a boolen (bool) value, to "False, the opposite boolean value.

Author

Commented:
Ah, thanks!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.