Datasheet
Listing 1-2: Altering the sequential progress of a wizard
protected void Wizard1_NextButtonClick(
object sender, WizardNavigationEventArgs e)
{
if (Wizard1.ActiveStepIndex == 0)
{
if (RadioButtonList1.SelectedValue == “Vegetarian”)
{
Wizard1.ActiveStepIndex = 2;
}
}
if (Wizard1.ActiveStepIndex == 1)
{
Wizard1.ActiveStepIndex = 3;
}
}
By capturing the NextButtonClick event, as shown in Listing 1-2, you can control the navigation sequence of
the Wizard. This event is called in the context of the current page when the Next button is clicked. Therefore,
check the ActiveStepIndex first to determine the current page, which is indicated by a zero-based integer. All
step controls are accessible during the postback, so we can get to their values easily. In this case, the code sets
the ActiveStepIndex to the Step 3 page, at index 2, if the eating preference is Vegetarian.
When the eating preference is Meat Eater, the Wizard will naturally navigate to Step 2, at index 1. In this
case, clicking the Next button should bring the user to Step 4, at index 3, to select a beverage. The
Vegetarian who navigated to Step 3 will naturally move to Step 4 after clicking the Next button.
When the Wizard reaches the end, the Next button will be replaced with a Finish button. You can cap-
ture an event from the Finish button to take action when it is clicked, as shown in Listing 1-3.
Listing 1-3: Handling the Finish button event
protected void Wizard1_FinishButtonClick(
object sender, WizardNavigationEventArgs e)
{
if (RadioButtonList1.SelectedValue == “Vegetarian”)
{
Response.Write(
“Your meal will be “ +
RadioButtonList3.SelectedValue +
“ and “ +
RadioButtonList4.SelectedValue);
}
else
{
Response.Write(
“Your meal will be “ +
RadioButtonList2.SelectedValue +
“ and “ +
RadioButtonList4.SelectedValue);
}
}
9
Hacks Revisited
04_597663 ch01.qxp 4/25/06 9:54 PM Page 9