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="txtProvi derId"
ControlToValidate="txtProv iderPasswo rd"
Display="None"
ErrorMessage="Provider password must be different from Provider ID"
Operator="NotEqual"
ValidationGroup="login"></ asp:Compar eValidator >
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
<asp:CompareValidator ID="cvProviderIDPswd" runat="server"
ControlToCompare="txtProvi
ControlToValidate="txtProv
Display="None"
ErrorMessage="Provider password must be different from Provider ID"
Operator="NotEqual"
ValidationGroup="login"></
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
Change your display property to anything other than Display="None"
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.
<asp:Button ID="btnLogin" runat="server" BorderStyle="Solid" Text="Log In" CssClass="Buttons" OnClick="btnLogin_Click" ValidationGroup="login"></
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
ASKER
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.
Thanks for you help.
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