Solved

Comparing two password fields in asp.net

Posted on 2003-11-06
2
390 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
2 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 50 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

18 Experts available now in Live!

Get 1:1 Help Now