DotNet Tutorials

V4 Dot Net Tutorials

Server Intellect Cloud Hosting

 Working with wizard control in ASP.NET 2.0 and VB.NET

The ASP.NET Wizard control simplifies many of the tasks that are associated with building multiple forms and collecting user input. The Wizard control provides a simple mechanism that allows you to easily build steps, add a new step, or reorder the steps. You can build linear and non-linear navigation and customize the control's user navigation without writing code. In this tutorial, we will show you to create a contact step by step using wizard control in ASP.NET 2.0 and VB.NET. First, import the namespace of System.Text.

The System.Text namespace contains classes representing ASCII, Unicode, UTF-7, and UTF-8 character encodings; abstract base classes for converting blocks of characters to and from blocks of bytes; and a helper class that manipulates and formats String objects without creating intermediate instances of String.

Imports System.Text

We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.


Then, add two events UserWizard_NextButtonClick and OnFinish in the Default.aspx page.

Protected Sub UserWizard_NextButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles UserWizard.NextButtonClick
If UserWizard.WizardSteps(e.NextStepIndex).StepType = WizardStepType.Finish Then
Dim sb As StringBuilder = New StringBuilder("")
sb.AppendFormat("UserName:{0}<br/>", Name.Text)
sb.AppendFormat("Position:{0}<br />", Seat.Text)
sb.AppendFormat("E-Mail:{0}<br />", Mail.Text)
sb.AppendFormat("Mobile:{0}<br />", Mobile.Text)
sb.AppendFormat("Notes:{0}<br /><hr>", Notes.Text)

LabMessage.Text = sb.ToString()
End If
End Sub

Protected Sub OnFinish(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles UserWizard.FinishButtonClick
LabFinish.Text = "Save Successfully."
End Sub

The front end Default.aspx page looks something like this:

<form id="Form1" runat="server">
<div>
<fieldset style="width: 310px">
<legend class="mainTitle">WizardDemo</legend>
<br />
<asp:Wizard ID="UserWizard" HeaderText="New an user" OnFinishButtonClick="OnFinish"
ActiveStepIndex="0" Height="120px" runat="server" BackColor="#FFFBD6" BorderColor="#FFDFAD"
BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" OnNextButtonClick="UserWizard_NextButtonClick">
<SideBarTemplate>
<div style="width: 90px;">
<asp:DataList runat="Server" ID="SideBarList">
<ItemTemplate>
<img src="Images/point.gif" />
<asp:LinkButton runat="server" ID="SideBarButton" ForeColor="#FFF277" Font-Underline="false"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</div>
</SideBarTemplate>
<WizardSteps>
<asp:WizardStep ID="WizardStep1" runat="server" Title="Name and Position">
<div style="width: 220px;">
<table>
<tr>
<td style="width: 60px; height: 42px">
UserName:</td>
<td style="height: 42px">
<asp:TextBox runat="server" ID="Name" />
<asp:RequiredFieldValidator runat="server" ID="NameValidator" Text="*" ErrorMessage="Please input UserName."
SetFocusOnError="True" ControlToValidate="Name" />
</td>
</tr>
<tr>
<td style="width: 60px">
Position:</td>
<td>
<asp:TextBox runat="server" ID="Seat" />
<asp:RequiredFieldValidator runat="server" ID="SeatValidator" Text="*" ErrorMessage="Please input Position."
SetFocusOnError="True" ControlToValidate="Seat" />
</td>
</tr>
<tr>
<td height="60" style="width: 60px">
</td>
<td valign="bottom">
<asp:ValidationSummary runat="server" DisplayMode="List" ID="Summary" />
</td>
</tr>
</table>
</div>
</asp:WizardStep>
<asp:WizardStep ID="WizardStep2" runat="server" Title="Contact">
<div style="width: 220px;">
<table>
<tr>
<td>
E-Mail:</td>
<td>
<asp:TextBox runat="server" ID="Mail" /></td>
</tr>
<tr>
<td>
Mobile:</td>
<td>
<asp:TextBox runat="server" ID="Mobile" /></td>
</tr>
<tr>
<td height="60">
</td>
</tr>
</table>
</div>
</asp:WizardStep>
<asp:WizardStep ID="WizardStep3" runat="server" Title="Notes">
<div style="width: 220px;">
<table>
<tr>
<td valign="top">
Notes:</td>
<td>
<asp:TextBox runat="server" ID="Notes" Rows="6" Columns="18" TextMode="MultiLine" /></td>
</tr>
</table>
</div>
</asp:WizardStep>
<asp:WizardStep ID="WizardStep4" runat="server" StepType="Finish" Title="Summary">
<div style="width: 220px;">
<asp:Label runat="server" ID="LabMessage" />
</div>
</asp:WizardStep>
<asp:WizardStep ID="WizardStep5" runat="server" StepType="Complete" Title="Finish">
<div style="width: 310px;">
<asp:Label runat="server" ID="LabFinish" />
</div>
</asp:WizardStep>
</WizardSteps>
<SideBarStyle BackColor="#990000" Font-Size="0.9em" VerticalAlign="Top" />
<NavigationButtonStyle Width="80px" BackColor="White" BorderColor="#CC9966" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#990000" />
<SideBarButtonStyle ForeColor="White" />
<HeaderStyle Height="24px" BackColor="#FFCC66" BorderColor="#FFFBD6" BorderStyle="Solid"
BorderWidth="2px" Font-Bold="True" Font-Size="0.9em" ForeColor="#333333" HorizontalAlign="Center" />
</asp:Wizard>
</fieldset>
</div>
</form>

The flow for the code behind page is as follows.

Imports System.Text

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub UserWizard_NextButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles UserWizard.NextButtonClick
If UserWizard.WizardSteps(e.NextStepIndex).StepType = WizardStepType.Finish Then
Dim sb As StringBuilder = New StringBuilder("")
sb.AppendFormat("UserName:{0}<br/>", Name.Text)
sb.AppendFormat("Position:{0}<br />", Seat.Text)
sb.AppendFormat("E-Mail:{0}<br />", Mail.Text)
sb.AppendFormat("Mobile:{0}<br />", Mobile.Text)
sb.AppendFormat("Notes:{0}<br /><hr>", Notes.Text)

LabMessage.Text = sb.ToString()
End If
End Sub

Protected Sub OnFinish(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles UserWizard.FinishButtonClick
LabFinish.Text = "Save Successfully."
End Sub
End Class

Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect and have been very happy. They are the most professional, customer service friendly and technically knowledgeable host we've found so far.




Looking for the C#.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!
Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!