Customizing the Appearance of ASP.NET Login Controls

You can customize the contents of several ASP.NET login controls by specifying control templates and adding your own controls to the user interface (UI) of the control, or by replacing or removing optional controls not required for the UI of the control.

You can also use the style properties of login controls as well as themes and skins to tailor the appearance of the control. For more information, refer to the members of the specific control and ASP.NET Themes and Skins Overview.

Customizable Login Controls

You can customize the content of any login control where the existing control UI can be replaced using a template. This includes the Login, PasswordRecovery, CreateUserWizard, and ChangePassword controls. The following table lists the templates that are available to customize with each control.

  • Login
    Use the LayoutTemplate template to specify different controls to retrieve a user name and password for logging in.

  • PasswordRecovery
    Use the UserNameTemplate template to specify different controls to retrieve the user name for which to recover the password.

    Use the QuestionTemplate template to specify different controls to retrieve the password question if the RequiresQuestionAndAnswer property is true.

    Use the SuccessTemplate template to specify different controls that appear when a user's password has been successfully recovered.

  • CreateUserWizard
    Use the ContentTemplate template of the CreateUserStep step to specify different controls to retrieve the user name, password, and other information required to create a new user account.

    Use the ContentTemplate template of the CompleteStep step to specify different controls that appear when the create user operation is complete.

  • ChangePassword
    Use the ChangePasswordTemplate template to specify different controls to retrieve the user name, current password, and new password for the user that is changing his or her password.

    Use the SuccessTemplate template to specify different controls that appear when a user's password has been successfully changed.

Specifying Controls in Login Control Templates

You can include additional controls and command buttons in login control templates as well as replace the default controls and command buttons with your own.

Replacing Command Buttons in a Login Control Template

You can use any control as a command button in a login control template. However, for the login control to recognize the command, the command control must bubble up an event that includes event arguments that inherit from the CommandEventArgs class. The command button must specify a value for the CommandName property of the CommandEventArgs class that identifies which command is to be executed by the login control. The following table lists the valid values for the CommandName property and their related login control templates.

Replacing Controls in a Login Control Template

You can replace the input and display controls used by several ASP.NET login controls in their respective templates. Each template has controls that must be included in the template as well as optional controls. Required and optional controls are identified using the ID property of the control. If a template does not include a control where the ID property is set to a required control identifier, or if that control does not implement the appropriate interface, the ASP.NET login control will throw an exception.

The following table lists the templates and the required controls by their ID properties.

  • Login.LayoutTemplate
    UserName - The account name of the user to be logged in. This control is required and must implement the IEditableTextControl interface.

    Password - The password of the user to be logged in. This control is required and must implement the IEditableTextControl interface.

    RememberMe - true to store the authentication token in a persistent cookie; false to store the authentication token in a session cookie. This control is optional and must implement the ICheckBoxControl interface.

    FailureText - Displays a login failure message. This control is optional and must implement the ITextControl interface.

  • PasswordRecovery.UserNameTemplate
    UserName - The account name of the user to recover the password for. This control is required and must implement the IEditableTextControl interface.

    FailureText - Displays a password recovery failure message. This control is optional and must implement the ITextControl interface.

  • PasswordRecovery.QuestionTemplate
    UserName - Displays the account name of the user that the password is being recovered for. This control is optional and must implement the ITextControl interface.

    Question - The password question for the user that the password is being recovered for. This control is optional and must implement the ITextControl interface.

    Answer - The password answer for the user that the password is being recovered for. This control is required and must implement the IEditableTextControl interface.

    FailureText - Displays a password recovery failure message. This control is optional and must implement the ITextControl interface.

  • CreateUserWizard.CreateUserStepContentTemplate
    UserName - The account name of the user account to be created. This control is required and must implement the IEditableTextControl interface.

    Password - The password for the user account to be created. This control is required and must implement the IEditableTextControl interface.

    ConfirmPassword - A confirmation value that must match the password. This control is optional and must implement the IEditableTextControl interface.

    Question - The password question for the user to be created. This control is required if the RequiresQuestionAndAnswer property is true and must implement the IEditableTextControl interface.

    Answer - The password answer for the user to be created. This control is required if the RequiresQuestionAndAnswer property is true and must implement the IEditableTextControl interface.

    Email - The e-mail address for the user account to be created. This control is required if the RequiresUniqueEmail property is true and must implement the IEditableTextControl interface.

    ErrorMessage - Displays a create user account failure message. This control is optional and must implement the ITextControl interface.

  • ChangePassword.ChangePasswordTemplate
    UserName - The account name of the user account to be created. This control is required if the DisplayUserName property is true and must implement the IEditableTextControl interface.

    CurrentPassword - The current password for the user account. This control is required and must implement the IEditableTextControl interface.

    NewPassword - The new password for the user account. This control is required and must implement the IEditableTextControl interface.

    ConfirmPassword - A confirmation value that must match the new password. This control is optional and must implement the IEditableTextControl interface.

    FailureText - Displays a create user account failure message. This control is optional and must implement the ITextControl interface.

Referencing a Control in a Login Control Template

To reference a control in a login control template, you can call the FindControl method of the container for the control template. The following table lists the templates and their associated container properties.

For example, if you were to include a DropDownList control with an ID of TimeZoneList in the ContentTemplate template of the CreateUserStep step of a CreateUserWizard control, you can reference the DropDownList control by calling the FindControl method of the ContentTemplateContainer container of the CreateUserStep property, as shown in the following example.

Protected Sub CreateUserWizard1_CreatedUser(sender As Object, e As EventArgs)
  Dim timeZoneList As DropDownList = _
    CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TimeZoneList"), DropDownList)
End Sub
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
  DropDownList timeZoneList = 
    (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TimeZoneList");
}

See Also

Concepts

Configuring an ASP.NET Application to Use Membership

Reference

ASP.NET Login Controls Overview