Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-02-04
7
Medium Priority
?
275 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 Ageil
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 26

Accepted Solution

by:
Alan Warren earned 2000 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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

636 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