Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparevalidator

Status
Not open for further replies.

keizersoz

Programmer
Apr 22, 2004
67
BE
I created a form with two textboxes and a button. The purpose of the first textbox is to collect a password and the purpose of the second textbox is to confirm the password. Now, I created on each textbox a requiredfieldvalidator. On top of that I created a comparevalidator. My question is the following. When is the comparevalidator (and requiredfieldvalidator) checking executed? Because after I type a password in the first textfield and press "tab" to go to the second textfield, I receive allready the comparevalidator error. I would like firstly, to give the chance to the user to enter both fields, and I would like the comparevalidator checking to appear only after the user pressed on the form button, otherwise it has no sense. How do I do this?

I added the code beneath:

<form runat="server">
Enter a Password:<br>
<asp:textbox id="Password" textmode="password"
runat="server" />
<asp:requiredfieldvalidator id="PasswordRequired"
controltovalidate="Password" runat="server" >
** Please Enter a Password
</asp:requiredfieldvalidator><br>

Confirm Password:<br>
<asp:textbox id="Confirm" textmode="password"
runat="server" />
<asp:requiredfieldvalidator id="ConfirmRequired"
controltovalidate="Confirm" runat="server" >
** Please Confirm Your Password
</asp:requiredfieldvalidator>

<asp:comparevalidator id="PasswordCompare"
controltovalidate="Password" controltocompare="Confirm"
type="string" runat="server">
** Your Password and Confirmation Don't Match
</asp:comparevalidator><br>
<br><br><asp:button text="Create" id="Create"
onclick="CreateButton_Click" runat="server"/><br>
<asp:label id="Status" runat="server" /><br>
</form>
 
keiz:

switch your compare and validate order, i.e.,

instead of:

controltovalidate="Password" controltocompare="Confirm"

try..

controltovalidate="Confirm" controltocompare="Password"
 
keiz: you might want to add the following Javascript, which will "click" the button after the second entry on using the "tab" to move -- makes the routine easier for the user. In your confirm textbox add:
Code:
<asp:textbox id="Confirm" textmode="password"
runat="server" onkeyPress="javascript:PushIt(event);return true;"/>
and then add the following javascript:
Code:
function PushIt(e){
 if (e.keyCode == 13) {
 frmValidate.buttVal.focus();
}
hope this helps...
 
When are the validators executed initially? After pressing tab, clicking a button? Refreshing the page?
 
By deafault they'll use built-in javascript and execute on the client side (which would be preferred in most situations) -- otherwise, you can change the property of the validator over to server control if you like.

At what point they trigger hard to say, perhaps on Lost Focus or blur, not sure (client side) or in code behind at the server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top