Figure 2

The <asp:createuserwizard> control handles gathering
up the user-account, email, password, and password recovery/answer data and
then calling into the ASP.NET 2.0 membership system to register the new user.
You simply have to override the control’s <createuserwizardstep> template
and customize the control layout to have things look how you want.
The sample is using the ASP.NET validation controls to
perform client-side validation on the inputs as well within the template
(example: making sure passwords match, the age is a valid integer, etc). One
added benefit in ASP.NET 2.0 is that these validation controls now support
client-side validation for FireFox and other modern browsers (note: all
screenshots were done using FireFox).
There are then three additional properties (their country,
gender and age) that I wanted to gather up about the new user as part of the
registration process. Doing this was pretty easy using the new ASP.NET 2.0
Profile system – simply add their definitions within the <profile> tag of
the web.config file to register them and store their values in the new profile
system:
Listing 1
<profile enabled="true">
<properties>
<add name="Country" type="string"/>
<add name="Gender" type="string"/>
<add name="Age" type="Int32"/>
</properties>
</profile>
I then handled the “CreatedUser” event on the
CreateUserWizard control within my CreateNewWizard.aspx.cs code-behind file to
retrieve the values from the controls within the CreateUserWizard control
template and set them in the profile store:
Listing 2
// CreatedUser event is called when a new user is successfully created
public void CreateUserWizard1_CreatedUser(object sender, EventArgs e) {
// Create an empty Profile for the newly created user
ProfileCommon p =
(ProfileCommon) ProfileCommon.Create(CreateUserWizard1.UserName, true);
// Populate some Profile properties off of the create user wizard
p.Country =
((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Country")).SelectedValue;
p.Gender =
((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Gender")).SelectedValue;
p.Age =
Int32.Parse(((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Age")).Text);
// Save profile - must be done since we explicitly created it
p.Save();
}
Because the user is being created as part of this step, I
explicitly choose to create a new Profile object in code (note that I was
passing in the CreatedUserWizard1.UserName property as the username – since the
user isn’t logged into the system yet). I then accessed the controls within
the template of the <asp:createuserwizard> control, pulled out their
values, and stuck them within the newly created profile. Calling p.save at the
end registered this profile with the new username. (Note: I’ll walk through
how we use this profile data later in a page below).