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>
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>