Creating a Basic ASP.NET Wizard Control
-
Adding a Wizard control to your page.
-
Adding controls and text to a wizard step.
-
Accessing the wizard's data between steps.
If you have already created a Web site (for example, by following the steps in Walkthrough: Creating a Basic Web Page in Visual Studio), 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.
This walkthrough uses a Web site project. You could use a Web application project instead. For information about the difference between these Web project types, see Web Application Projects versus Web Site Projects.
To create a file system Web site
-
Open Visual Web Developer (or Visual Studio).
-
On the File menu, click New Web 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.
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.
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.
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.
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.
|