October 24, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

The Web Form Wizardry of ASP.NET 2.0's Wizard Control

  • July 5, 2006
  • By Bipin Joshi
  • Send Email »
  • More Articles »

Wizard Control Events

In order to make some use of the information captured via the wizard, you need to handle some of the Wizard control's events. The Wizard control has several useful events. The following table lists some of the important ones:

Event Name Description
ActiveStepChanged This event is raised when the currently displayed step of the Wizard control changes.
CancelButtonClick This event is raised when the Cancel button of the wizard step is clicked.
FinishButtonClick This event is raised when the Finish button of the wizard step is clicked.
NextButtonClick This event is raised when the Next button of the Wizard is clicked.
PreviousButtonClick This event is raised when the Previous button of the Wizard is clicked.
SideBarButtonClick This event is raised when any of the side bar link buttons of the Wizard are clicked.

In this example, you will handle two events of the Wizard control: ActiveStepChanged and FinishButtonClick. Go in the code behind of the Web form and add the following code in ActiveStepChanged event handler:

protected void Wizard1_ActiveStepChanged(object sender, EventArgs e)
{
if (Wizard1.ActiveStep.ID == "step3")
{
Label9.Text = ((TextBox)Wizard1.Controls[0].FindControl("TextBox1")).Text;
Label10.Text = ((TextBox)Wizard1.Controls[0].FindControl("TextBox4")).Text;
Label11.Text = ((TextBox)Wizard1.Controls[0].FindControl("TextBox5")).Text;
}
}

As you can see, this event grabs all the values entered on the "Account Details" and "Contact Information" steps. First of all, it checks the ID property of the ActiveStep property. (Remember that you set the ID property of the Confirmation step to step3.) It accesses the controls from the wizard step by using the FindControl() method, which accepts the ID of the control to be searched and returns a reference to it. The return value of the FindControl() method is of generic type control; hence, it type casts it into a TextBox.

Finally, add the following code in the FinishButtonClick event of the Wizard control:

protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
Label12.Text = "Thank you for registering with us";
Wizard1.Visible=false;
}

Here, you simply display a success message in a Label control and hide the Wizard control. Most real world cases will have some code that stores the values into the database.

Run the Web form to see the Wizard control in action. Try navigating between various steps. Also, test the validation controls. You will notice that if you do not satisfy the validation conditions and click the Previous button, the validation is not performed. If you click on any side bar links, the validation is always triggered.

That's it! Your user registration wizard is ready.

Author Note: This article uses the user registration wizard as a common example to teach the Wizard control. ASP.NET 2.0 provides a specialized form of the Wizard control called CreateUserWizard, which works along with membership features.

The Wizard Control

The Wizard control introduced in ASP.NET 2.0 makes creating Wizard-driven Web forms easy. It consists of several WizardSteps, and each step contains a set of controls. The functionality of navigating between the wizard steps is automatically provided by the Wizard control. Using various events of the Wizard control you can tap the step navigation and wizard completion.

Download the Code

Download the code that accompanies the examples in this article.

About the Author

Bipin Joshi is the founder and owner of BinaryIntellect Consulting, where he conducts professional training programs on .NET technologies. He is the author of Developer's Guide to ASP.NET 2.0 and co-author of three WROX press books on .NET 1.x. He also is a Microsoft MVP, member of ASPInsiders, MCAD, and MCT.





Page 2 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel