Sponsored Ad

Thursday, June 17, 2010

How to Compaire/Validate Two Password Values in ASP.NET | CompareValidator

Suppose you have two password fields and you want to copaire these fields that original password and reentered passwords are same or not?

Here is a simple solution to do client side validation. Use ASP.NET comparevalidator and assign these properties.

ControlToValidate="txtPassword1" ControlToCompare="txtPassword2"

Set type =”string”

And its all done. Now if you will enter wrong repassword then it will validate client side and prompt you with error.

How to Compaire/Validate Two Password Values in ASP.NET | CompareValidator

How to Compaire/Validate Two Password Values in ASP.NET | CompareValidator

 

How to Compaire/Validate Two Password Values in ASP.NET | CompareValidator Example:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<body>
    <form id="Form1" runat="server">
        <h4>
            Compare Two Password Values</h4>
       Password Value 1:
        <asp:TextBox ID="txtPassword1" TextMode="Password" runat="server" />
        <br />
        <br />
        Password Value 2:
        <asp:TextBox ID="txtPassword2" TextMode="Password" runat="server" />
        <br />
        <br />
        <br />
        <asp:Button ID="Button1" Text="Validate" runat="server" />
        <br />
        <br />   
        <asp:CompareValidator ID="compair_Password_values"  ControlToValidate="txtPassword1" ControlToCompare="txtPassword2"
            ForeColor="red" Type="string"  Text="Please enter same Password values in both textboxes." Operator="equal"
            runat="server" />
    </form>
</body>
</html>

No comments:

Post a Comment

Sponsored Ad

Development Updates