Solved

Comparing two password fields in asp.net

Posted on 2003-11-06
2
392 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 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