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:
<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:
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
if(!IsPasswordsEqual(Textbox1.Text,TextBox2.Text))
{
MessageBox.Show("Enter same password in both");
}