Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [213]

By Root 5614 0
is not used unless the sidebar is enabled. If the sidebar is enabled, the title of each step is used to create a list of steps. If the sidebar is enabled but no title is provided for the various steps, the ID of the WizardStep objects is used to populate the sidebar, as shown earlier in Figure 9-8.

While defining a step, you can also set the AllowReturn property, which indicates whether the user is allowed to return to the current step from a subsequent step. The default value of the property is true.

Types of Wizard Steps


The StepType property indicates how a particular step should be handled and rendered within a wizard. Acceptable values for the step type come from the WizardStepType enumeration, as listed in Table 9-10.

Table 9-10. Wizard Step Types

Property

Description

Auto

The default setting, which forces the wizard to determine how each contained step should be treated.

Complete

The last page that the wizard displays, usually after the wizard has been completed. The navigation bar and the sidebar aren’t displayed.

Finish

The last page used for collecting user data. It lacks the Next button, and it shows the Previous and Finish buttons.

Start

The first screen displayed, with no Previous button.

Step

All other intermediate pages, in which the Previous and Next buttons are displayed.

When the wizard is in automatic mode—the default type Auto—it determines the type of each step based on the order in which the steps appear in the source code. For example, the first step is considered to be of type Start and the last step is marked as Finish. No Complete step is assumed. If you correctly assign step types to your wizard steps yourself, rather than use the Auto type, the order in which you declare your steps in the .aspx source is not relevant.

Creating an Input Step


The following code shows a sample wizard step used to collect the provider name and the connection string to connect to a database and search for some data. For better graphical results, the content of the step is encapsulated in a fixed-height

tag. If all the steps are configured in this way, users navigating through the wizard won’t experience sudden changes in the overall page size and layout:

Provider

text="System.Data.SqlClient" />

Connection String

text="SERVER=(local);DATABASE=northwind;... " />

Figure 9-9 shows a preview of the step. As you could probably guess, the step is recognized as a Start step. As a result, the wizard is added only to the Next button.

Figure 9-9. A sample Start wizard step.

A wizard is usually created for collecting input data, so validation becomes a critical issue. You can validate the input data in two nonexclusive ways—using validators and using transition event handlers.

The first option involves placing validator controls in the wizard step. This guarantees that invalid input—empty fields or incompatible data types—is caught quickly and, optionally, already on the client:

text="*"

errormessage="Must indicate a connection string"

setfocusonerror="true"

controltovalidate="ConnString" />

If you need to access server-side resources to validate the input data, you’re better off using transition event handlers. A transition event is an event the wizard raises when it is about to switch to another view. For example, the NextButtonClick event is raised when the user clicks the Next button to jump to the subsequent step. You can intercept this event, do any required validation, and cancel the transition if necessary. I’ll return to this topic in a moment.

Defining the Sidebar


The sidebar is a left-side panel that lists buttons to quickly and randomly reach any step of the wizard. It’s a sort

®Online Book Reader