Solved

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

Posted on 2014-02-04
7
259 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
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now