Export (0) Print
Expand All

CreateUserWizard Class

Note: This class is new in the .NET Framework version 2.0.

Provides a user interface for creating new Web site user accounts.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

[BindableAttribute(false)] 
public class CreateUserWizard : Wizard
/** @attribute BindableAttribute(false) */ 
public class CreateUserWizard extends Wizard
BindableAttribute(false) 
public class CreateUserWizard extends Wizard

The CreateUserWizard control provides the user interface for the MembershipProvider object that communicates with your Web site's user data store to create new user accounts in the data store. The CreateUserWizard relies on the MembershipProvider to create the user and disable them if necessary.

By default, the CreateUserWizard control will accept a user name and password from the Web site visitor. Based on the requirements of the site's MembershipProvider object, the CreateUserWizard control will optionally accept an e-mail address, represented by the Email property, and a password recovery confirmation question and answer, represented by Question and Answer. For a table showing all required and optional controls for CreateUserWizard, see CreateUserStep.

NoteImportant:

If AutoGeneratePassword is set to true and the PasswordStrengthRegularExpression property is set in the application's Web.config file, you could potentially generate a password that does not pass the regular expression strength test. In this case, creating a user raises an error that indicates an invalid password.

Creating a User

When a user is created with the CreateUserWizard, the control interacts with the current MembershipProvider to accomplish the following tasks in order.

  1. Create a password if AutoGeneratePassword is set to true.

  2. Create the user in the data store that the MembershipProvider represents.

  3. Disable the user in the store if the DisableCreatedUser property is set to true.

You can extend the CreateUserWizard control to accept additional information by adding additional fields, or by adding additional steps before or after the provided templates in the CreateUserStep and CompleteStep properties.

NoteNote

The CreateUserWizardStep step is the first step within the CreateUserWizard control, and is a required step. By default, the AllowReturn property is set to false to keep the user from returning to the CreateUserWizardStep step and accidentally attempting to create another user account with the same credentials. If EnableViewState is set to false, the AllowReturn property is not maintained in view state and you must include logic in your application to maintain the AllowReturn value.

CreateUserWizard control properties represented by text boxes, such as UserName, are accessible during all phases of the page life cycle. The control will pick up any changes made by the end user by means of the TextChanged event triggered by the textboxes.

The CreateUserWizard control can optionally send e-mail messages to new users if you have configured an SMTP mail server to send e-mail. For more information, see the MailDefinition property.

NoteNote

The CreateUserWizard control uses Internet e-mail services to send login information to users. There are inherent security risks with sending passwords in e-mail. You should determine whether these security risks are acceptable to your site.

Styles and Templates

When the CreateUserWizard control is not customized with templates, the AccessKey property of the CreateUserWizard control applies to the first text box in the control and the TabIndex property, which is applied to all text boxes of the control. If the CreateUserWizard control is customized with templates, then the AccessKey property and the TabIndex property are ignored. In this case, directly set the AccessKey property and the TabIndex property of each template child control.

CreateUserWizard control properties represented by text boxes, such as UserName and Password, are accessible during all phases of the page life cycle. The control will pick up any changes made by the end user by means of the TextChanged event triggered by the textboxes.

NoteNote

Setting the AutoGeneratePassword, MembershipProvider, or RequireEmail property recreates the child controls of the CreateUserWizard control, and their control state is lost in the process. To avoid this situation, explicitly maintain the control state of the CreateUserWizard control's child controls, or avoid putting controls inside of templates.

The following table lists the CreateUserWizard control style properties and explains which UI element each style property affects. For a list of which properties each style applies to, see the documentation for the individual style properties.

Style property

UI element affected

ContinueButtonStyle

Continue button.

CreateUserButtonStyle

Create User button.

HyperLinkStyle

Links to other pages.

InstructionTextStyle

Instructional text on the page that tells users how to use the control.

LabelStyle

Labels for all input fields, such as text boxes.

TextBoxStyle

Text entry input fields.

TitleTextStyle

Title text for each view.

CompleteSuccessTextStyle

Text displayed to the user when the password recovery or reset attempt is successful.

ErrorMessageStyle

Error messages when the membership provider fails to create a new user account.

PasswordHintStyle

The text that describes password requirements.

ValidatorTextStyle

Error messages associated with validation.

Validation Grouping

The CreateUserWizard control uses a validation group so that other fields on the same page as the CreateUserWizard control can be validated separately. By default, the ID property of the CreateUserWizard control is used as the name of the validation group. For example, a CreateUserWizard control with the ID "CreateUserWizard1" will use a validation group name of "CreateUserWizard1". If you want to set the validation group that the CreateUserWizard control is part of, you must template the control and change the validation group name.

Note that the CreateUserWizard class inherits from the Wizard class, which does not support special Microsoft Internet Explorer rendering for non-standard or quirks mode. The CreateUserWizard does not attempt to optimize rendering for non-standard Internet Explorer mode. To get the best Internet Explorer rendering using the CreateUserWizard control, use the XHTML doc type, which is added by default in Visual Web Developer and Visual Studio.

Accessibility

The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.

TopicLocation
How to: Customize the ASP.NET CreateUserWizard ControlBuilding ASP .NET Web Applications
How to: Enable User RegistrationBuilding ASP .NET Web Applications
How to: Customize the ASP.NET CreateUserWizard ControlBuilding ASP .NET Web Applications
How to: Enable User RegistrationBuilding ASP .NET Web Applications

The first code example shows how to use the CreateUserWizard control in its basic form. This page will create a new Web site user account with the site's default MembershipProvider object.

<%@ page language="C#"%>

<script runat="server">

</script>

<html>
<head runat="server">
    <title>CreateUserWizard basic sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:createuserwizard id="Createuserwizard1" runat="server" >
      </asp:createuserwizard>
    </div>
    </form>
</body>
</html>

The second code example shows how to use the CreateUserWizard control with the default templates.

<%@ page language="C#"%>

<script runat="server">

</script>

<html>
<head runat="server">
    <title>CreateUserWizard Sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:createuserwizard id="Createuserwizard1" runat="server">
        <wizardsteps>
          <asp:createuserwizardstep runat="server" title="Sign Up for Your New Account">
            <contenttemplate>
              <table border="0">
                <tr>
                  <td>
                    <table border="0" style="height: 100%; width: 100%;">
                      <tr>
                        <td align="center" colspan="2">
                          Sign Up for Your New Account</td>
                      </tr>
                      <tr>
                        <td align="right">
                          <asp:label runat="server" associatedcontrolid="UserName" id="UserNameLabel">
                            User Name:</asp:label></td>
                        <td>
                          <asp:textbox runat="server" id="UserName"></asp:textbox>
                          <asp:requiredfieldvalidator runat="server" controltovalidate="UserName" tooltip="User Name is required."
                            id="UserNameRequired" validationgroup="Createuserwizard1" errormessage="User Name is required.">
                            *</asp:requiredfieldvalidator>
                        </td>
                      </tr>
                      <tr>
                        <td align="right">
                          <asp:label runat="server" associatedcontrolid="Password" id="PasswordLabel">
                            Password:</asp:label></td>
                        <td>
                          <asp:textbox runat="server" textmode="Password" id="Password"></asp:textbox>
                          <asp:requiredfieldvalidator runat="server" controltovalidate="Password" tooltip="Password is required."
                            id="PasswordRequired" validationgroup="Createuserwizard1" errormessage="Password is required.">
                            *</asp:requiredfieldvalidator>
                        </td>
                      </tr>
                      <tr>
                        <td align="right">
                          <asp:label runat="server" associatedcontrolid="ConfirmPassword" id="ConfirmPasswordLabel">
                            Confirm Password:</asp:label></td>
                        <td>
                          <asp:textbox runat="server" textmode="Password" id="ConfirmPassword"></asp:textbox>
                          <asp:requiredfieldvalidator runat="server" controltovalidate="ConfirmPassword" tooltip="Confirm Password is required."
                            id="ConfirmPasswordRequired" validationgroup="Createuserwizard1" errormessage="Confirm Password is required.">
                            *</asp:requiredfieldvalidator>
                        </td>
                      </tr>
                      <tr>
                        <td align="right">
                          <asp:label runat="server" associatedcontrolid="Email" id="EmailLabel">
                            Email:</asp:label></td>
                        <td>
                          <asp:textbox runat="server" id="Email"></asp:textbox>
                          <asp:requiredfieldvalidator runat="server" controltovalidate="Email" tooltip="Email is required."
                            id="EmailRequired" validationgroup="Createuserwizard1" errormessage="Email is required.">
                            *</asp:requiredfieldvalidator>
                        </td>
                      </tr>
                      <tr>
                        <td align="right">
                          <asp:label runat="server" associatedcontrolid="Question" id="QuestionLabel">
                            Security Question:</asp:label></td>
                        <td>
                          <asp:textbox runat="server" id="Question"></asp:textbox>
                          <asp:requiredfieldvalidator runat="server" controltovalidate="Question" tooltip="Security question is required."
                            id="QuestionRequired" validationgroup="Createuserwizard1" errormessage="Security question is required.">
                            *</asp:requiredfieldvalidator>
                        </td>
                      </tr>
                      <tr>
                        <td align="right">
                          <asp:label runat="server" associatedcontrolid="Answer" id="AnswerLabel">
                            Security Answer:</asp:label></td>
                        <td>
                          <asp:textbox runat="server" id="Answer"></asp:textbox>
                          <asp:requiredfieldvalidator runat="server" controltovalidate="Answer" tooltip="Security answer is required."
                            id="AnswerRequired" validationgroup="Createuserwizard1" errormessage="Security answer is required.">
                            *</asp:requiredfieldvalidator>
                        </td>
                      </tr>
                      <tr>
                        <td align="center" colspan="2">
                          <asp:comparevalidator runat="server" display="Dynamic" errormessage="The Password and Confirmation Password must match."
                            controltocompare="ConfirmPassword" controltovalidate="Password" id="PasswordCompare"
                            validationgroup="Createuserwizard1">
                          </asp:comparevalidator>
                        </td>
                      </tr>
                      <tr>
                        <td align="center" colspan="2" style="color: Red;">
                          <asp:literal runat="server" enableviewstate="False" id="FailureText">
                          </asp:literal>
                        </td>
                      </tr>
                    </table>
                  </td>
                </tr>
              </table>
            </contenttemplate>
          </asp:createuserwizardstep>
          <asp:completewizardstep runat="server" title="Complete">
            <contenttemplate>
              <table border="0">
                <tr>
                  <td>
                    <table border="0" style="height: 100%; width: 100%;">
                      <tr>
                        <td align="center" colspan="2">
                          Complete</td>
                      </tr>
                      <tr>
                        <td>
                          Your account has been successfully created.</td>
                      </tr>
                      <tr>
                        <td align="right" colspan="2">
                          <asp:button runat="server" validationgroup="Createuserwizard1" commandname="Continue"
                            id="ContinueButton" causesvalidation="False" text="Continue" />
                        </td>
                      </tr>
                    </table>
                  </td>
                </tr>
              </table>
            </contenttemplate>
          </asp:completewizardstep>
        </wizardsteps>
      </asp:createuserwizard>
    </div>
    </form>
</body>
</html>

The third code example adds an additional step to the CreateUserWizard control and uses the CreatedUser event to store the user's first and last name in personalization properties. The code example requires the following entries in the Web.config file.

<configuration>

<system.web>

<profile>

<properties>

<add name="lastName" />

<add name="firstName" />

</properties>

</profile>

</system.web>

</configuration>

<%@ page language="C#"%>
<script runat="server">
void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
  Profile.SetPropertyValue("UserName",firstName.Text + " " + lastName.Text);  
}
</script>
<html>
  <head runat="server">
    <title>
      CreateUserWizard.CreatedUser sample</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <div>
        <asp:createuserwizard id="CreateUserWizard1" runat="server">
          <wizardsteps>
            <asp:wizardstep runat="server" steptype="Start" title="Identification">
              Tell us your name:<br />
              <table width="100%">
                <tr>
                  <td>
                    First name:</td>
                  <td>
                    <asp:textbox id="firstName" runat="server" /></td>
                </tr>
                <tr>
                  <td>
                    Last name:</td>
                  <td>
                    <asp:textbox id="lastName" runat="server" /></td>
                </tr>
              </table>
            </asp:wizardstep>
            <asp:createuserwizardstep runat="server" title="Sign Up for Your New Account">
            </asp:createuserwizardstep>
          </wizardsteps>
        </asp:createuserwizard>
      </div>
    </form>
  </body>
</html>

System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
       System.Web.UI.WebControls.CompositeControl
         System.Web.UI.WebControls.Wizard
          System.Web.UI.WebControls.CreateUserWizard

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft