2.4 How to use the ASP.NET ChangePassword control

ASP.NET 2.0’s new ChangePassword control gives you the ability to automate the process of a user wanting to change their password. You can configure the new ChangePassword control to accepts the username and the password the user wishes to change. You can also configure it such that the user cannot enter his username, but should be logged into the application as a user to change the password.The new ChangePassword control also can be configured such that after changing the password, the new password can be e-mailed back to the user.

The ChangePassword control in its simplest form will look like the following:

<asp:ChangePassword ID="ChangePassword1" runat="server">

The ChangePassword control can send a new password e-mail to the user using the <MailDefinition> child element. The following is a sample code of how this will look like:

    <asp:ChangePassword id="ChangePassword1" runat="Server" >
            Subject="Subject Line"


  • The body of the e-mail message will be taken from the file "BodyFile.txt " in the BodyFileName attribute.
  • This .txt file can include <%UserName%> and <%Password%> so you can put the user’s account name and password into the email.

In ASP.NET 2.0, you have the ability to customize your ChangePassword control by using any of the optional attributes listed below.




The ID for the ChangePassword control


runat="Server" is needed for all ASP.NET server controls.


The URL for the image used for the Cancel button.


The text for the Cancel button.


The Cancel button type can be Button, Link, or Image.


The URL of the page after the Cancel button is clicked.


The URL for the Change Password button image on the Success page.


The ChangePassword button text.


The ChangePassword button type can be Button,“Link, or Image.


The text if the password change is failed.


The text for the ChangePassword title area.


The text for the ConfirmPassword label field.


The URL for the Continue button image.


The Continue button text.


The Continue button type can be Button, Link, or Image.


The URLof page the user is taken to after clicking the Continue button.


The text for the CreateUser link.


The URL for theCreateUser page.


This is a Boolean check box, to indicate if you want the user to enter the username when changing the password or the user to be loggied in to the system. If True, the ChangePassword control can also be used to change the password of an account other than the one to which the user is currently logged in, if False they can only change the password of the logged in account.


The text for the instructions to use the ChangePassword control.


The text for the New Password label field.


The regular expression which is used as a validation for the new password.


The text diplyed for the instruction for the new password and its requiermetns, like how many character, minimum length, etc…


The text displayed for the Current Password label field.


The text for the Password Recovery page link


The URL for the Password Recovery page.


The URL for theSuccess page if the password has been changed.


The text for the message if the password change is successful, and this is not displayed if the SuccessPageUrl is provided.


The text for the Username label field.

Attributes for the “ChangePassword” control

The following is the code for a customized ChangePassword control.

    <asp:ChangePassword id="ChangePassword1" runat="Server"
        ChangePasswordTitleText="Change Your Password<br />"
        PasswordLabelText="Enter your current password:"
        NewPasswordLabelText="Enter the new password:"
        ConfirmNewPasswordLabelText="Confirm the new password:">


  • The ChangePassword control requires the user to be logged in to change the password by default. You can change this by specifying the DiplayeUsername=True attribute. This will display a Useraname "textbox, where the user has to enter the valid user name and password to change the password for any user.
  • The ChangePassword control has two views, and they are:
    • The Initial view – this is the Change Password view including the text boxes for the user to enter the new password.
    • The Success view – displayed when the password change is successful with a confirmation message. The success view is not displayed if the SuccessPageUrl is provided, but instead the page in the URL specified will be shown.

Table of Contents