Link to home
Start Free TrialLog in
Avatar of Maria Torres
Maria Torres

asked on

ASP.NET CompareValidator: Verifying that UserID and Password are not the same

I have two text boxes: txtProviderId and txtProviderPassword.  I'm trying to compare the values, verifying that they are not same; user id and password cannot be the same.  I'm using the CompareValidator control and the code is as follows:

<asp:CompareValidator ID="cvProviderIDPswd" runat="server"
        ControlToCompare="txtProviderId"
        ControlToValidate="txtProviderPassword"
        Display="None"
        ErrorMessage="Provider password must be different from Provider ID"
        Operator="NotEqual"
        ValidationGroup="login"></asp:CompareValidator>


When I test my program and add the same value to both textboxes, the CompareValidator control is not detecting that they are not equal and I do not an error message.

Can someone please tell me what I am doing wrong?  Thank you
Avatar of duttcom
duttcom
Flag of Australia image

What event is validating the textbox values? The validation is usually carried out when a button is clicked, or some other event occurs and then another control (such as a label) will be set to display the error message. Just having the validator in the page is not enough.

Look at the example in the link below. You will see that there is a text box to validate, a button that gets clicked to do the validation and a label that has its text updated to display the error message.

http://msdn.microsoft.com/en-us/library/db330ayw(v=vs.85).aspx
Change your display property to anything other than Display="None"
Avatar of Maria Torres
Maria Torres

ASKER

The event that is validating the textbox is a button.  I only provided the comparevalidator statement, but the statement for the button is as follows:

<asp:Button ID="btnLogin" runat="server" BorderStyle="Solid" Text="Log In" CssClass="Buttons" OnClick="btnLogin_Click" ValidationGroup="login"></asp:Button>

Please note that I'm also using the ValidationSummary Control which is used to display a summary of all validation errors occurred in a Web page.  This control works for all other textboxes but the two that I am comparing.  

Any thoughts?

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Alan Warren
Alan Warren
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Alan,  I noticed that in your code you did not include the statement "Operator = 'Not Equal'".  How are you instructing the program to compare for inequality?
Hi CarmenMTorres,
I must have dropped that when copying or editing the sample code in this editor.

The code I posted would currently be triggering on the default operator value of "Equal"{0} and should be set to Operator = 'Not Equal'{1}.


Respectfully yours,
Alan
Thanks Alan.  I have to go back and do some more investigation.  Somehow the code is not detecting that password and userId are the same.

Thanks for you help.