Walkthrough: Creating a Basic ASP.NET Wizard Control
Building a series of forms to collect user data is a common task when developing Web sites. The ASP.NET Wizard control simplifies many of the tasks associated with building forms and collecting user input by providing a mechanism that allows you to easily build steps, add a new step, or reorder the steps. In this walkthrough, you will use the ASP.NET Wizard control to simplify data collection as a series of independent steps without having to write code or making user data persist between form steps. You will create a simple wizard that collects a user name and e-mail address, and then present it back to the user in the completion step. Tasks illustrated in this walkthrough include:
Adding a Wizard control to your page.
Adding controls and text to a wizard step.
Accessing the wizard's data between steps.
Prerequisites
In order to complete this walkthrough, you will need:
- Visual Studio or Visual Web Developer.
Creating the Web Site
If you have already created a Web site (for example, by following the steps in Walkthrough: Creating a Basic Web Page in Visual Web Developer), you can use that Web site and skip to "Adding a Wizard Control" later in this walkthrough. Otherwise, create a new Web site and page by following these steps.
To create a file system Web site
Open Visual Web Developer (or Visual Studio).
On the File menu, click NewWeb Site.
The New Web Site dialog box appears.
Under Visual Studio installed templates, click ASP.NET Web Site.
In the Location box, enter the name of the folder where you want to keep the pages of your Web site.
For example, type the folder name C:\WebSites.
In the Language list, click the programming language you prefer to work in.
Click OK.
Visual Web Developer creates the folder and a new page named Default.aspx.
Adding a Wizard Control
To add a Wizard control
Switch to Design view for Default.aspx.
From the Standard tab of the Toolbox, drag a Wizard control onto the page.
The control appears with two default steps already in place. Clicking the steps allows you to edit the text and controls displayed during that step.
Editing Wizard Steps
When the Wizard control is dragged onto the page, it shows two predefined steps by default. For this walkthrough, you will edit both steps, and add a completion step that shows the result of the first two steps: a user name and an e-mail address.
To edit the first wizard step
Drag one of the handles at the edge of the Wizard control to enlarge the control to about twice its default size.
Click the underlined text Step 1 in the Wizard control.
Click the edit area for the Wizard control.
You can now edit the step's display area.
Type Name:.
Drag a TextBox control onto the active area of the wizard, next to the text you just typed.
You can now edit the second step to collect a user's e-mail address.
To edit the second wizard step
Click Step 2 in the Wizard control.
Click the edit area for the Wizard control.
Type Email:.
Drag a TextBox control onto the active area of the wizard, next to your e-mail label.
Save the file.
Adding a Completion Step
You will now create a completion step that acts as the end point of your wizard. The Complete step has no navigational options.
To add a completion step
Right-click the Wizard control.
Choose Show Smart Tag.
In the Wizard Tasks dialog box, choose Add/Remove Wizard Steps.
The WizardStep Collection Editor appears.
From the Add drop-down list on the Add button, select Wizard Step.
The Properties area now shows the new step.
Set the Title property to Finished.
Set the StepType property to Complete.
Click OK.
Now you can edit your new completion step. For the purposes of this walkthrough, configure the completion step to show the data the user entered on the previous steps.
To edit the completion step
Right-click the Wizard control and choose Show Smart Tag.
In the Wizard Tasks dialog box, use the Step drop-down list to choose the Finished step.
Note
The name in the drop-down list will be the name you gave the step when you created it, Finished in this example.
Drag a Label control onto the wizard, leaving the default name of Label1.
Drag another Label control onto the wizard, leaving the default name of Label2.
Save the file.
The completion step will display the data entered by the user. Use the page's Load event to assign the values from the first two steps to the labels you added to the completion step.
To show the user's data
Return to Default.aspx and, in Design view, double-click the design surface.
The page now contains a Page_Load method that is stubbed out for you.
Add the following highlighted code.
Private Sub Page_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) _ Handles Me.Load Label1.Text = TextBox1.Text Label2.Text = TextBox2.Text End Sub
void Page_Load(Object sender, System.EventArgs e) { Label1.Text = TextBox1.Text; Label2.Text = TextBox2.Text; }
Save the file.
Testing the Wizard Control
Now you can test the Wizard control.
To test the Wizard control
View Default.aspx in Design view.
Display the Wizard Tasks menu on the control and select Step 1 from the Step drop-down list.
Click the Wizard control, and then press CTRL+F5.
Type a name in the name TextBox control for Step 1.
Click Next.
Type an e-mail address in the e-mail TextBox control for Step 2.
Click Finish.
Your data is displayed.
Next Steps
The Wizard control simplifies the creation of forms to gather user data. In addition to what has been covered here, you might have other questions related to user data collection and forms use. For example, you might want to:
Learn more about authenticating users with Forms. For details, see How to: Implement Simple Forms Authentication
Use themes to enhance the appearance of your wizard. For details, see ASP.NET Themes and Skins Overview
Get an overview of the Wizard control. For details, see Wizard Web Server Control Overview