ASP.NET Wizard control using VB.NET

In this article you will learn that what is Wizard control,its property and how you can use this control.
  • 1069
Download Files:
 

Introduction
 
In this article I am explaining the working of a Wizard control. 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. The wizard control handles all of the basic functionality involved in navigating the user through a series of steps. The most common use of Wizard control is in collecting information. The Wizard control comes in handy whenever you need to do a number of related things in sequence.

Properties of Wizard control

  • WizardSteps:- A collection of WizardStep object 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.
Getting Started
  • Simply create a new ASP.NET web application. 
  • Drag a Wizard control on the page. You can find the Wizard control in standard tab of Toolbox.
  • Your page should very much Look like below image.

    Wizard7.gif
     
  • Still in design view make sure "step1" is still active and drag a Label and Textbox control in to the Wizard. Name the Label lblName and its Text to "Name", Change the Name of the Textbox to txtName. Your page should look very much like the image below.

    Wizard1.gif
     
  • Next click on "step2" in order to begin the editing on second Wizard. Once again drag a Label and Textbox on to the Wizard. This time you are going to ask for an email address instead of a name so name the Label lblEmail and its Text to E-Mail, change the name of the Textbox to txtEmail. Your page should very much look like the below image.

    Wizard2.gif
     
  • The source mode of your page will look like below.

    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="Wizard_control.WebForm1" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <
    body>
        <form id="form1" runat="server">
        <
    div>
              <asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0" Height="123px"
                style="width: 209px">
                <WizardSteps>
                    <asp:WizardStep runat="server" title="Step 1">
                        <asp:Label ID="lblName" runat="server" Text="Name"></asp:Label>
                        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                    </asp:WizardStep>
                    <asp:WizardStep runat="server" title="Step 2">
                        <asp:Label ID="lblEmail" runat="server" Text="E-Mail"></asp:Label>
                        &nbsp;
                        <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
                    </asp:WizardStep>
                </WizardSteps>
            </asp:Wizard>
            <asp:Literal ID="litFinished" runat="server"></asp:Literal>
        </div>
        </form>
    </body>
    </
    html>
     
  • Now add a Literal control below to the Wizard and name it litFinished. 
  • Now double click on the Finish button and add the below code.

    Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick
            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>")
            Wizard1.Visible = False
            litFinished.Text = myStringBuilder.ToString
        End Sub

     
  • 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. 
  • Now run your application.

Output

Wizard3.gif

Wizard4.gif

Wizard5.gif

Wizard6.gif

Summary

In this article you learned that how you can use a Wizard control and its properties in collecting user information in ASP.NET.

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.