Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have created user name, password and confirm password using Textbox. My query is what we are typing in password we should type in confirm password if not it should shows errors. For this how should write the code.

Regards
Balamurugan
Posted
Comments
y.dsandeepnaidu 10-Oct-12 2:36am    
if ((txtBox2.Text == "") && (txtbox3.Text == ""))
{
MessageBox.Show("pass is correct");
}
else
{
messagebox.show("u entered wrong password");
}

1 solution

You can use Compare Validator Control which allows you to compare the value entered by the user into an input control.

Look some more details: ASP.NET CompareValidator Control[^]

Try this code:
XML
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" />

<asp:RequiredFieldValidator ID="req6" runat="server" ControlToValidate="txtPassword" Text="*" />

Confirm Password <asp:TextBox ID="txtPasswordC" runat="server" TextMode="Password" />

<asp:CompareValidator runat="server" ID="Comp1" ControlToValidate="txtPassword" ControlToCompare="txtPasswordC" Text="Password mismatch" />


Here is similar discussion on same:
Compare Validator Issue in Change Password Screen[^]
Use CompareValidator to check password field and confirm password field[^]

[EDIT]
Try this:
C#
public bool IsPasswordsEqual(string password1, string password2)
{
	if (password1.Equals(password2))
        {
		return true;
	}

	return false;
}

use this method on submit button click event or confirmpassword textbox leave event
as
C#
if(!IsPasswordsEqual(Textbox1.Text,TextBox2.Text))
{
    MessageBox.Show("Enter same password in both");
}
 
Share this answer
 
v2
Comments
[no name] 27-Jul-12 1:13am    
I'm asking in C# windows form...
Prasad_Kulkarni 27-Jul-12 1:13am    
..but where you mentioned that in your question.
[no name] 27-Jul-12 1:28am    
I have used your code but it s not working...
Prasad_Kulkarni 27-Jul-12 1:31am    
What exactly not working means.
Is it giving any error or anything else? elaborate.
Prasad_Kulkarni 27-Jul-12 1:16am    
Please see my updated answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900