CompareValidator inside UpdatePanel - VS2008

I am using UpdatePanel and want to put CompareValidator in two text boxes to make sure the user entered password and confirmation match.

This works fine (I have VS2008 and I am using .NET 3.5), with one minor issue:

Validation ends as soon as the user leaves the first text box before being able to enter the second. This doesn't cause any REAL problems, programmatically (whatever happens shows an error message, it disappears when they enter confirmation), but our testers say it's a problem. It will not pass the UA test until the test lights up, until it clicks the Save button.

How do I get the CompareValidator so that it doesn't fire until they have entered text in both fields?

EDIT:

Here's an example of the markup.

    <div>
        <div><asp:Label runat="server" ID="lblPassword" Text="Password"/></div>
        <div><asp:TextBox runat="server" TextMode="password" ID="txtPassword" size="25" /></div>    
    </div>
    <div>
        <div><asp:Label runat="server" ID="lblConfirmPassword" Text="Confirm Password"/></div>
        <div><asp:TextBox runat="server" TextMode="password" ID="txtConfirmPassword" size="25" /></div>
    </div>
    <asp:CompareValidator ID="CompareValidator1" ValidationGroup="PublishPassValidation" ControlToValidate="txtPassword" ControlToCompare="txtConfirmPassword" runat="server" ErrorMessage="Passwords do not match"></asp:CompareValidator>

      

The above element is inside the control contained in the ContentTemplate from the UpdatePanel on the page.

(CSS classes and styles have been removed for brevity)

0


source to share


3 answers


Try toggling it so that validation is done in the confirmation text box and not the password text box. This way, it won't fire until you change the confirmation text box or the form is submitted. And you probably want to have a required field validator in your password textbox.



<div>
    <div><asp:Label runat="server" ID="lblPassword" Text="Password"/></div>
    <div><asp:TextBox runat="server" TextMode="password" ID="txtPassword" size="25" />
         <asp:RequiredFieldValidator runat="server" ID="passwordRequiredValidator"
                                     ControlToValidate="txtPassword"
                                     ValidationGroup="PublishPassValidation"
                                     ErrorMessage="Password is required."  />    
    </div>    
</div>
<div>
    <div><asp:Label runat="server" ID="lblConfirmPassword" Text="Confirm Password"/></div>
    <div><asp:TextBox runat="server" TextMode="password" ID="txtConfirmPassword" size="25" /></div>
</div>
<asp:CompareValidator ID="CompareValidator1" ValidationGroup="PublishPassValidation"
                      ControlToValidate="txtConfirmPassword"
                      ControlToCompare="txPassword" runat="server"
                      ErrorMessage="Passwords do not match">
</asp:CompareValidator>

      

+1


source


You can turn off client side validation for this validator.

EnableClientScript="false"

      



This would mean giving back to the server to report an invalid state, and you would need to make sure you check if the page is actually valid before proceeding.

Page.Validate("PublishPassValidation");

if (Page.IsValid)
{
    // Do Stuff
}

      

+1


source


I have a feeling that you have children included in the update panel?

Do users press "ENTER" in the password field? Can you confirm that, for some reason, the refresh bar is doing a partial refresh after moving focus?

If so, it will lead to verification.

+1


source







All Articles