Online Book Reader

Home Category

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

By Root 5777 0

{

args.IsValid = false;

if (String.Equals(args.Value, "Dino"))

args.IsValid = true;

}

The preceding code sets the page’s IsValid property to false if the text box contains anything other than “Dino.” However, this fact alone doesn’t prevent the transition to the target page. In other words, you could still have invalid input data posted to the target page.

Fortunately, this issue has an easy workaround, as shown in the following code:

if (!PreviousPage.IsValid)

{

Response.Write("Sorry, the original page contains invalid input.");

Response.End();

return;

}

In the target page, you test the IsValid property on the PreviousPage property and terminate the request in the case of a negative answer. However, to avoid a server request and, worse yet, a page transition, you can add a client check to the CustomValidator control:

Text="*"

ControlToValidate="Keyword"

ClientValidationFunction="ensureValidKeywords"

OnServerValidate="EnsureValidKeywords" />

Here’s a possible implementation of the JavaScript function:

Working with Wizards


An input form is used to collect data from users. However, it is not unusual that the amount of data to be collected is quite large and dispersed. In these cases, a single form is hardly the right solution. A wizard is a sequence of related steps, each associated with an input form and a user interface.

Wizards are typically used to break up large forms to collect user input. Users move through the wizard sequentially, but they are normally given a chance to skip a step or jump back to modify some of the entered values. A wizard is conceptually pretty simple, but implementing it over HTTP connections can be tricky. In ASP.NET, you have a readymade server control—the Wizard control—that automates many of the tasks.

An Overview of the Wizard Control


The Wizard control supports both linear and nonlinear navigation. It allows you to move backward to change values and skip steps that are unnecessary because of previous settings or because users don’t want to fill in those fields. Like many other ASP.NET controls, the Wizard control supports themes, styles, and templates.

Wizard is a composite control and automatically generates some constituent controls, such as navigation buttons and panels. As you’ll see in a moment, the programming interface of the control has multiple templates that provide for in-depth customization of the overall user interface. The control also guarantees that state is maintained no matter where you move—backward, forward, or to a particular page. All the steps of a wizard must be declared within the boundaries of the same Wizard control. In other words, the wizard must be self-contained and not provide page-to-page navigation.

Structure of a Wizard


As shown in Figure 9-7, a wizard has four parts: a header, view, navigation bar, and sidebar.

Figure 9-7. The four parts of a Wizard control.

The header consists of text you can set through the HeaderText property. You can change the default appearance of the header text by using its style property; you can also change the structure of the header by using the corresponding header template property. If HeaderText is empty and no custom template is specified, no header is shown for the wizard.

The view displays the contents of the currently active step. The wizard requires you to define each step in an element. An element corresponds to a WizardStep control. Different types of wizard steps are supported; all wizard step classes inherit from a common base class named WizardStepBase.

All wizard steps must be grouped in a single tag, as shown in the following code:

Return Main Page Previous Page Next Page

®Online Book Reader