Solved

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

Posted on 2014-02-04
7
264 Views
Last Modified: 2014-04-03
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
0
Comment
Question by:CarmenMTorres
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 12

Expert Comment

by:duttcom
ID: 39834381
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
0
 
LVL 27

Expert Comment

by:Sammy
ID: 39834817
Change your display property to anything other than Display="None"
0
 

Author Comment

by:CarmenMTorres
ID: 39836032
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.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 26

Accepted Solution

by:
Alan Warren earned 500 total points
ID: 39963201
Hi CarmenMTorres,

It works fine here, am I missing something?
Q_28356397
<%@ Page Language="VB" %>

<!DOCTYPE html>

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

      <asp:TextBox ID="txtProviderId" runat="server"></asp:TextBox>
      <asp:TextBox ID="txtProviderPassword" runat="server" TextMode="Password"></asp:TextBox>
      <asp:CompareValidator ID="cv1" runat="server" 
        ErrorMessage="Password and ProviderID cannot be the same!" 
        ValidationGroup="login" Display="None" 
        ControlToCompare="txtProviderId" ControlToValidate="txtProviderPassword" />
      <asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="login" />
      <asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="login" />
    </div>
    </form>
</body>
</html>

Open in new window

Respectfully yours,
Alan
0
 

Author Comment

by:CarmenMTorres
ID: 39966477
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?
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 39968168
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
0
 

Author Comment

by:CarmenMTorres
ID: 39972087
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question