You can use the approach explained in the article How to use ASP.NET Membership CreateUserWizard control to create additional wizard steps. In this case you need to handle events and perform some actions within event procedures. For example if you are planning to collect additional information from the user with the wizard, you have to store it somewhere and for that reason you should execute SQL statements against your database. The next table lists the events specific to the CreateUserWizard control. The control also inherits all the events from the Wizard control.

Event Descritpion
ContinueButtonClick Raised when the user clicks the Continue button in the last wizard step.
CreatingUser

Raised by the wizard before it creates the new user through the membership API.

CreatedUser After the user has been created successfully, the control raises this event.
CreateUserError If the creation of the user was not successful, this event is raised.
SendingMail The control can send an e-mail to the created user if a mail server is configured. This event is raised by the control before the e-mail is sent so that you can modify the contents of the mail message.
SendMailError If the control was unable to send the message—for example, because the mail server was unavailable—it raises this event.

If you want to add a wizard step for querying additional user information, such as the first name and the last name, you should save this information to a custom database table. When running through the wizard, you cannot store the information into the profile, because the user is not authenticated yet.  Therefore, you either have to store it in a custom database table or include a way for the user to edit the profile after the registration process. If you want to save additional data within the CreateUser event, you have to collect this information in previous steps, because this event is raised immediately after the CreateUserWizardStep has been completed successfully. For this purpose, it’s sufficient to place other wizard steps prior to the <asp:CreateUserWizardStep> tag. The next code lines show this approach:

 

<form id=”form1″ runat=”server”>

<div align=”center”>

<asp:CreateUserWizard runat=”server” ID=”RegisterUserCtrl” MembershipProvider=”AspNetSqlMembershipProvider”

BorderStyle=”Solid” BackColor=”Silver”>

<WizardSteps>

<asp:WizardStep ID=”NamesStep” AllowReturn=”True”>

<table>

<tr>

<td align=”left”>

FirstName:

</td>

<td>

<asp:TextBox ID=”FirstName” runat=”server”></asp:TextBox>

</td>

</tr>

<tr>

<td align=”left”>

LastName:

</td>

<td>

<asp:TextBox ID=”LastName” runat=”server”></asp:TextBox>

</td>

</tr>

<tr>

<td align=”left”>

Age:

</td>

<td>

<asp:TextBox ID=”AgeText” runat=”server”></asp:TextBox>

</td>

</tr>

</table>

</asp:WizardStep>

<asp:CreateUserWizardStep>

</asp:CreateUserWizardStep>

<asp:CompleteWizardStep>

</asp:CompleteWizardStep>

</WizardSteps>

</asp:CreateUserWizard>

</div>

</form>

 

The next pictures show the result:

 

 

Membership API CreateUserWizard control events in C#

Membership API CreateUserWizard control events in C#

Now you can store additional information in your data store when the CreatedUser event is raised by the control, as follows:

 

protected void RegisterUser_CreatedUser(object sender, EventArgs e)

{

short _Age;

string _FirstName, _LastName;

// Find the correct wizard step

WizardStepBase step = null;

for (int i = 0; i < RegisterUserCtrl.WizardSteps.Count; i++)

{

if (RegisterUserCtrl.WizardSteps[i].ID == “NamesStep”)

{

step = RegisterUserCtrl.WizardSteps[i];

break;

}

}

if (step != null)

{

_ FirstName = ((TextBox)step.FindControl(“FirstName”)).Text;

_ LastName = ((TextBox)step.FindControl(“LastName”)).Text;

_Age = short.Parse(((TextBox)step.FindControl(“AgeText”)).Text);

// Store the information

// This is just simple code you need to replace with code

// for really storing the information

System.Diagnostics.Debug.WriteLine(

string.Format(“{0} {1} {2}”, _ FirstName, _ LastName, _Age));

}

}

 

In the CreatedUser event, the code just looks for the wizard step with the ID set to NamesStep. Then it uses the FindControl method several times for getting the controls with the actual content. As soon as you have retrieved the controls where the user entered his first name, last name, and age, you can access their properties and perform any action you want with them.