asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

An Introduction to the ASP.NET 2.0 Wizard Control
By John Peterson
Rating: 3.9 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article



  • download source code
  • Those of us who use Windows all know what wizards are, and whether you love them or hate them, they've become a fixture in the modern computing landscape. For those of you who don't already know, according to Wikipedia, "A wizard is an interactive computer program which acts as an interface to lead a user through a complex task, using step-by-step dialogs."

    This article serves as an introduction to the ASP.NET 2.0 Wizard Control. It starts with a brief overview and then walks you through the steps involved in building a complete web form that utilizes a wizard to collect informatin from a user.

    The ASP.NET 2.0 Wizard Control

    In classic ASP and ASP.NET 1.x, if you wanted to use a wizard-like interface, you were pretty much forced to build one on your own. In ASP.NET 2.0 Microsoft introduced the Wizard control. The control handles all of the basic functionality involved in navigating the user through a series of steps. The most common use is for collecting information, but there's no rule that says that's the only thing you can use it for. The wizard control comes in handy whenever you need to do a number of related things in sequence.

    In it's simplest form, the Wizard control itself is defined on your ASP.NET 2.0 Webform as follows:

    <asp:Wizard id="myWizard" runat="server">
    </asp:Wizard>
    

    Aside from a few basic properties and a bunch of formatting attributes, there's really not much to the Wizard control. Most of the wizard functionality actually comes from four sub-objects:

    • WizardSteps - a collection of WizardStep objects each representing a step in the completion of the Wizard.
    • Navigation Area - this is where the "Previous" and "Next" buttons are located.
    • SideBar - an optional navigation bar that lists all the WizardSteps and allows you to move from step to step in any sequence.
    • Header - a header for the Wizard that is displayed on every step.

    Your First Wizard

    Now that you know what a wizard is and the names of the objects we'll be working with, it's time to build our first wizard using the ASP.NET 2.0 Wizard control. It's going to be very simple and honestly it's not going to do very much, but it'll serve as a starting point and will begin to familiarizing you with the elements involved.

    I'm going to be building my samples using Microsoft Visual Web Developer 2005 Express Edition. While you certainly don't need VWD 2005 in order to use the code from this article, if you are interested in getting a copy, it's available as a free download from the Visual Studio Express web site.

    1. Load Visual Web Developer and create a new "ASP.NET Web Site" project named "Wizard".

         

    2. Once the site is created, add a new "Web Form" named "wizard_basic.aspx"

    3. If it's not already open, open the new "wizard_basic.aspx" page and switch to design view.

    4. Drag a Wizard control on to the page. You'll find the Wizard control on the "Standard" tab in the VS2005 "Toolbox".

    5. Your page should now look similar to this:

    6. Next, change the title of the page to "Wizard Sample - Basic" and rename the wizard "myWizard".

    7. Still in design view, make sure "Step 1" is still active and drag a Label and TextBox control into the Wizard. Name the Label "lblName", set it's text to "Name:", and make it bold. Change the name of the TextBox to "txtName".

      Your page should look very much like the image above.

    8. Next, click on "Step 2" in order to begin editing the second WizardStep. Once again, drag a Label and TextBox onto the Wizard. This time we're going to ask for an e-mail address instead of a name so name the Label "lblEmail", set it's text to "E-mail:", and make it bold. Change the name of the TextBox to "txtEmail". When you're done your page should look something like this:

      All that's left now is to do something with the data we gather when the user presses the "Finish" button. In a real application, it would probably get stored in a database or sent via email, but to keep things simple, I'll simply echo it back out to the web page.

    9. Add a Literal control below the wizard and name it "litFinished".

    10. If you double click on the "Finish" button in the wizard, VWD will take you into source view and will create an empty Sub called "myWizard_FinishButtonClick". Paste the following code into the Sub.

          Dim myStringBuilder As New StringBuilder()
          
          myStringBuilder.AppendLine("<p><strong>Here's what you entered:</strong></p>")
          myStringBuilder.AppendLine("<pre>")
          myStringBuilder.AppendLine("<strong>Name:</strong> " & txtName.Text)
          myStringBuilder.AppendLine("<strong>E-mail:</strong> " & txtEmail.Text)
          myStringBuilder.AppendLine("</pre>")
          
          myWizard.Visible = False
          litFinished.Text = myStringBuilder.ToString

      The code simply hides the Wizard and copies the data entered to the Literal control added in the previous step.

    11. The final step is to change back to design mode and make sure that the first WizardStep of the Wizard control is the active one. This sets the ActiveStepIndex to "0" so that the Wizard starts on the first step when the page is run.

    12. That's it. Now we run the code and this is what we get:

      Once the forms are filled out and submitted the page will look something like this:

    Now I know that it's not the prettiest thing around, but it's a good basic starting point.

    A Better Looking Wizard

    For the more advanced wizard, instead of explaining each step I'm just going to mention the highlights, but the code in the zip file is pretty straight-forward. So here's a list of the main changes from the simple version you just built above.

    • Added a HeaderTemplate that displays the current step number out of the total number of steps.
    • Added another step and a bunch more fields.
    • Gave the steps more descriptive names.
    • Applied the "Simple" auto formatting scheme from VWD.

    And here's what this version looks like when run in IE:

    Get the Code

    You can download a zip file containing both samples above from here (2.7 KB). The code doesn't require any real setup or configuration. Just unzip the files to a web server with ASP.NET 2.0 or later installed and they should run fine.

    Conclusion

    I hope this article has shown you how simple it can be to use the new ASP.NET 2.0 Wizard control to make your multi-page forms easier to manage. Aside from building the individual WizardSteps and processing the data when the wizard is finished, the control does most of the work for you. And while it's outside the scope of this discussion, the controls have an set of Styles and Templates that you can work with in order to get your pages to look exactly as you'd like.

    For more information on the wizard control, you may want to read the Wizard Control Reference from the ASP.NET 2.0 Quickstart.

    For those of you who are still running ASP.NET 1.x, you might want to check out my ASP.NET Wizard Sample at ASP 101. It's not as elegant as the ASP.NET 2.0 Wizard, but it gets the job done and the way the panels are laid out actually makes converting to the Wizard quite painless.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Jul 21, 2005 - N-Tier Web Applications using ASP.NET 2.0 and SQL Server 2005 - Part 1
    While the .NET Framework made building ASP.NET applications easier then it had ever been in the past, .NET 2.0 builds on that foundation in order to take things to the next level. This article shows you to how to construct an N-Tier ASP.NET 2.0 Web application by leveraging the new features of ASP.NET 2.0 and SQL Server 2005.
    [Read This Article]  [Top]
    Apr 28, 2005 - New Files and Folders in ASP.NET 2.0
    With the release of ASP.NET 2.0, Microsoft has greatly increased the power of ASP.NET by introducing a suite of new features and functionalities. As part of this release, ASP.NET 2.0 also comes with a host of new special files and folders that are meant to be used to implement a specific functionality. This article examines these new files and folders in detail and provides examples that demonstrate how to utilize them to create ASP.NET 2.0 applications.
    [Read This Article]  [Top]
    Mar 10, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 2, Cont'd
    Alex Homer continues his detailed look at the major changes to the DataSet class. In this part, he looks at two features that allow developers to work with data in a more structured and efficient way when using the DataSet with a SQL Server 2005 database server.
    [Read This Article]  [Top]
    Mar 9, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 2
    Alex Homer continues his detailed look at the major changes to the DataSet class. In this part, he looks at two features that allow developers to work with data in a more structured and efficient way when using the DataSet with a SQL Server 2005 database server.
    [Read This Article]  [Top]
    Mar 3, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 1, Cont'd
    In this article, Alex Homer looks at the changes between the version 1.x and version 2.0 DataSet and their associated classes, showing you how you can take advantage of the new features to improve your applications' capabilities and performance.
    [Read This Article]  [Top]
    Mar 2, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 1
    In this article, Alex Homer looks at the changes between the version 1.x and version 2.0 DataSet and their associated classes, showing you how you can take advantage of the new features to improve your applications' capabilities and performance.
    [Read This Article]  [Top]
    Feb 16, 2005 - Writing a Custom Membership Provider for the Login Control in ASP.NET 2.0
    In ASP.NET 2.0 and Visual Studio 2005, you can quickly program custom authentication pages with the provided Membership Login controls. In this article, Dina Fleet Berry examines the steps involved in using the Login control with a custom SQL Server membership database.
    [Read This Article]  [Top]
    Dec 29, 2004 - ClickOnce Deployment in .NET Framework 2.0
    In this article, Thiru Thangarathinam examines .NET 2.0's new ClickOnce deployment technology that is designed to ease deployment of Windows forms applications. This new technology not only provides an easy application installation mechanism, it also eases deployment of upgrades to existing applications.
    [Read This Article]  [Top]
    Dec 15, 2004 - A Sneak Peek at ASP.NET 2.0's Administrative Tools
    With ASP.NET 2.0, Microsoft has made great strides in increasing developer productivity and has made implementing previously complex solutions relatively easy. Where this version of ASP.NET really shines, however, is in its new administrative tools that allow developers to spend less time managing the configuration of the servers and software and more time developing great code.
    [Read This Article]  [Top]
    Nov 17, 2004 - The ASP.NET 2.0 TreeView Control
    Thiru Thangarathinam introduces ASP.NET 2.0's new TreeView control which provides a seamless way to consume and display information from hierarchical data sources. The article discusses this new control in depth and explains how to use this feature rich control in your ASP.NET applications.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry

    internet.commediabistro.comJusttechjobs.comGraphics.com

    Search:

    WebMediaBrands Corporate Info

    Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
    Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs