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:
Now you can store additional information in your data store when the CreatedUser event is raised by the control, as follows:
Protected Sub RegisterUserCtrl_CreatedUser(sender As Object, e As EventArgs) Handles RegisterUserCtrl.CreatedUser
Dim _Age As Short
Dim _FirstName, _LastName As String
‘ Find the correct wizard step
Dim Item As System.Web.UI.Control
Dim _Step As WizardStepBase = Nothing
For Each Item In RegisterUserCtrl.WizardSteps
If Item.ID = “NamesStep” Then
_Step = Item
Exit For
End If
Next
If Not IsNothing(_Step) Then
_FirstName = CType(_Step.FindControl(“FirstName”), TextBox).Text
_LastName = CType(_Step.FindControl(“LastName”), TextBox).Text
_Age = CShort(CType(_Step.FindControl(“Age”), TextBox).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))
End If
End Sub
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.