?
Solved

Comparing two password fields in asp.net

Posted on 2003-11-06
2
Medium Priority
?
398 Views
Last Modified: 2006-11-17

                                                Pasword<asp:textbox id="txtPassword" class="textarea" textmode="password" runat="server"/>
                                                <asp:requiredfieldvalidator id="validatePassword" runat="server" errormessage="<br/>Please Enter Password. " controltovalidate="txtPassword" display="dynamic"/>
                                                <asp:RegularExpressionValidator runat="server" ControlToValidate="txtPassword" ValidationExpression="[0-9a-zA-Z]{5,10}" ErrorMessage= "<br/>Login Id should be 5 to 10 characters or numbers." display="dynamic"/>

Repassword                                                <asp:textbox id="txtRePassword" class="textarea" textmode="password" runat="server"/>
                                                <asp:requiredfieldvalidator id="validaterePassword" runat="server" errormessage="<br/>Please Enter Re-Password. " controltovalidate="txtRePassword" display="dynamic"/>
                                                <asp:RegularExpressionValidator runat="server" ControlToValidate="txtRePassword" ValidationExpression="[0-9a-zA-Z]{5,10}" ErrorMessage= "<br/>Login Id should be 5 to 10 characters or numbers." display="dynamic"/>
                                                <asp:CompareValidator
                                                 ControlToValidate="txtPassword"
                                                 ControlToCompare="txtRePassword"
                                                 Display="Dynamic"
                                                 Text="<br/>Password and Re-Password does not match."
                                                 Runat="Server" />

I'm try to compare two password field from the above code.the code is working fine the only problem is that.
when the form loads it is obvious that both fields are blank.And when i type in the Password field and move to the next Re-password field that without me typing anything in Re-password field it already compares the value and gives me the Error msg (Password and Re-Password does not match.).

should it compare the values in the two textbox only after i've typed on both the text boxes or when i click the button.

thanks
0
Comment
Question by:swech
[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
2 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 200 total points
ID: 9694227
you have the Validator set in REVERSE.  YOu want the validator to Validate txtRePassword against txtPassword, but you have it set backwards:

as you have it now coded:

asp:CompareValidator
                                         ControlToValidate="txtPassword"
                                         ControlToCompare="txtRePassword"
                                         Display="Dynamic"
                                         Text="<br/>Password and Re-Password does not match."
                                         Runat="Server" />

and it should be:

asp:CompareValidator
                                         ControlToValidate="txtRePassword"
                                         ControlToCompare="txtPassword"
                                         Display="Dynamic"
                                         Text="<br/>Password and Re-Password does not match."
                                         Runat="Server" />

that way the validation is not done until the txtRePassword TEXT is entered.

AW
0
 

Author Comment

by:swech
ID: 9694316
thanks for quick response.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

771 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