ASP.Net/Asp Control/Wizard
Содержание
Basic Wizard
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="BasicWizard" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Wizard ID="Wizard1"
runat="server"
Width="467px"
BackColor="#EFF3FB"
BorderColor="#B5C7DE"
BorderWidth="1px"
Font-Names="Verdana"
CellPadding="5"
ActiveStepIndex="0"
Font-Size="Small"
OnFinishButtonClick="Wizard1_FinishButtonClick">
<WizardSteps>
<asp:WizardStep ID="WizardStep1" runat="server" Title="Personal">
<h3>Personal Profile</h3>
Preferred Programming Language:
<asp:DropDownList ID="lstLanguage" runat="server">
<asp:ListItem>C#</asp:ListItem>
<asp:ListItem>VB .NET</asp:ListItem>
<asp:ListItem>J#</asp:ListItem>
<asp:ListItem>Java</asp:ListItem>
<asp:ListItem>C++</asp:ListItem>
<asp:ListItem>C</asp:ListItem>
</asp:DropDownList>
<br />
</asp:WizardStep>
<asp:WizardStep ID="WizardStep2"
runat="server"
Title="Company">
<h3>Comany Profile</h3>
Number of Employees: <asp:TextBox ID="txtEmpCount" runat="server"></asp:TextBox><br />
Number of Locations: <asp:TextBox ID="txtLocCount" runat="server"></asp:TextBox>
</asp:WizardStep>
<asp:WizardStep ID="WizardStep3"
runat="server"
Title="Software">
<h3>Software Profile</h3>
Licenses Required:
<asp:CheckBoxList ID="lstTools" runat="server">
<asp:ListItem>Visual Studio</asp:ListItem>
<asp:ListItem>Office</asp:ListItem>
<asp:ListItem>Windows 2003 Server</asp:ListItem>
<asp:ListItem>SQL Server 2005</asp:ListItem>
<asp:ListItem>BizTalk 2004</asp:ListItem>
</asp:CheckBoxList>
</asp:WizardStep>
<asp:WizardStep ID="Complete" runat="server" Title="Complete " StepType="Complete">
Summary: <asp:Label ID="lblSummary" runat="server" Text="Label"></asp:Label>
</asp:WizardStep>
</WizardSteps>
<SideBarStyle VerticalAlign="Top" />
</asp:Wizard>
</div>
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
public partial class BasicWizard : System.Web.UI.Page
{
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.Append("<b>You chose: <br />");
sb.Append("Programming Language: ");
sb.Append(lstLanguage.Text);
sb.Append("<br />Total Employees: ");
sb.Append(txtEmpCount.Text);
sb.Append("<br />Total Locations: ");
sb.Append(txtLocCount.Text);
sb.Append("<br />Licenses Required: ");
foreach (ListItem item in lstTools.Items)
{
if (item.Selected)
{
sb.Append(item.Text);
sb.Append(" ");
}
}
sb.Append("</b>");
lblSummary.Text = sb.ToString();
}
}
Checkout wizard
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Checkout" %>
<!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 id="Head1" runat="server">
<title>Chapter 20 Checkout Wizard</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<strong>Halloween Superstore - Checkout</strong><br />
<br />
<asp:Wizard ID="wizCheckout" runat="server" Width="739px"
DisplayCancelButton="True"
OnCancelButtonClick="wizCheckout_CancelButtonClick" >
<WizardSteps>
<asp:WizardStep ID="WizardStep1" runat="server"
Title="Step 1: Contact Info">
Please enter your contact information:<br /><br />
<table>
<tr>
<td>
First Name:
</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server"
Height="22px" Width="200px"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="txtFirstName"
ErrorMessage="First Name is required."></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Last name:
</td>
<td>
<asp:TextBox ID="txtLastName" runat="server"
Height="22px" Width="200px"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2"
runat="server"
ControlToValidate="txtLastName"
ErrorMessage="Last Name is required."></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Email:
</td>
<td>
<asp:TextBox ID="txtEmail" runat="server"
Height="22px" Width="200px"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator3"
runat="server"
ControlToValidate="txtEmail"
ErrorMessage="Email is required."></asp:RequiredFieldValidator>
</td>
</tr>
</table>
</asp:WizardStep>
<asp:WizardStep ID="WizardStep2" runat="server"
Title="Step 2: Shipping Method">
Please select a shipping method:<br /><br />
<asp:RadioButton ID="rdoUPSGround" runat="server"
Checked="True" GroupName="ShipVia" Text="UPS Ground" />
<br />
<asp:RadioButton ID="rdoUPS2Day" runat="server"
GroupName="ShipVia" Text="UPS Second Day" />
<br />
<asp:RadioButton ID="rdoFedEx" runat="server"
GroupName="ShipVia" Text="Federal Express Overnight" />
<br />
</asp:WizardStep>
<asp:WizardStep ID="WizardStep3" runat="server"
Title="Step 3: Credit Card Info">
Please enter your credit card information:<br />
<br />
<table>
<tr>
<td>
<asp:ListBox ID="lstCardType"
runat="server">
<asp:ListItem Selected="True"
Value="VISA">Visa</asp:ListItem>
<asp:ListItem Value="MC">
MasterCard</asp:ListItem>
<asp:ListItem Value="AMEX">
American Express</asp:ListItem>
</asp:ListBox>
</td>
<td>
Card Number:
</td>
<td>
<asp:TextBox ID="txtCardNumber" runat="server"
Height="22px" Width="262px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Expiration Date:
</td>
<td valign="middle">
<asp:DropDownList ID="ddlExpirationMonth"
runat="server">
<asp:ListItem Value="1">January</asp:ListItem>
<asp:ListItem Value="2">February</asp:ListItem>
<asp:ListItem Value="3">March</asp:ListItem>
<asp:ListItem Value="4">April</asp:ListItem>
<asp:ListItem Value="5">May</asp:ListItem>
<asp:ListItem Value="6">June</asp:ListItem>
<asp:ListItem Value="7">July</asp:ListItem>
<asp:ListItem Value="8">August</asp:ListItem>
<asp:ListItem Value="9">September</asp:ListItem>
<asp:ListItem Value="10">October</asp:ListItem>
<asp:ListItem Value="11">November</asp:ListItem>
<asp:ListItem Value="12">December</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlExpirationYear"
runat="server">
</asp:DropDownList>
</td>
</tr>
</table>
</asp:WizardStep>
</WizardSteps>
</asp:Wizard>
</div>
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Checkout : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
wizCheckout.ActiveStepIndex = 0;
int year = DateTime.Now.Year;
for (; year < DateTime.Now.Year + 6; year++)
ddlExpirationYear.Items.Add(year.ToString());
}
}
protected void wizCheckout_CancelButtonClick(object sender, EventArgs e)
{
wizCheckout.ActiveStepIndex = 0;
txtFirstName.Text = "";
txtLastName.Text = "";
txtEmail.Text = "";
rdoUPSGround.Checked = true;
rdoUPS2Day.Checked = false;
rdoFedEx.Checked = false;
lstCardType.SelectedIndex = 0;
txtCardNumber.Text = "";
ddlExpirationMonth.SelectedIndex = 0;
ddlExpirationYear.SelectedIndex = 0;
}
}
Checkout wizard (VB)
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Checkout" %>
<!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 id="Head1" runat="server">
<title>Chapter 20 Checkout Wizard</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Wizard ID="wizCheckout" runat="server" ActiveStepIndex="0"
Width="739px" >
<WizardSteps>
<asp:WizardStep ID="WizardStep1" runat="server"
Title="Step 1: Contact Info">
Please enter your contact information:<br /><br />
<table>
<tr>
<td>First Name:</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server"
Height="22px" Width="200px"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="txtFirstName"
ErrorMessage="First Name is required."></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Last name:</td>
<td>
<asp:TextBox ID="txtLastName" runat="server"
Height="22px" Width="200px"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2"
runat="server"
ControlToValidate="txtLastName"
ErrorMessage="Last Name is required."></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Email:</td>
<td>
<asp:TextBox ID="txtEmail" runat="server"
Height="22px" Width="200px"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator3"
runat="server"
ControlToValidate="txtEmail"
ErrorMessage="Email is required."></asp:RequiredFieldValidator>
</td>
</tr>
</table>
</asp:WizardStep>
<asp:WizardStep ID="WizardStep2" runat="server"
Title="Step 2: Shipping Method">
Please select a shipping method:<br /><br />
<asp:RadioButton ID="rdoUPSGround" runat="server"
Checked="True" GroupName="ShipVia" Text="UPS Ground" />
<br />
<asp:RadioButton ID="rdoUPS2Day" runat="server"
GroupName="ShipVia" Text="UPS Second Day" />
<br />
<asp:RadioButton ID="rdoFedEx" runat="server"
GroupName="ShipVia" Text="Federal Express Overnight" />
<br />
</asp:WizardStep>
<asp:WizardStep ID="WizardStep3" runat="server"
Title="Step 3: Credit Card Info">
Please enter your credit card information:<br />
<br />
<table>
<tr>
<td>
<div style="text-align: right">
<asp:ListBox ID="lstCardType"
runat="server">
<asp:ListItem Selected="True"
Value="VISA">Visa</asp:ListItem>
<asp:ListItem Value="MC">
MasterCard</asp:ListItem>
<asp:ListItem Value="AMEX">
American Express</asp:ListItem>
</asp:ListBox>
</div>
</td>
<td>Card Number:</td>
<td>
<asp:TextBox ID="txtCardNumber" runat="server"
Height="22px" Width="262px"></asp:TextBox>
</td>
</tr>
<tr>
<td>Expiration Date:
</td>
<td valign="middle">
<asp:DropDownList ID="ddlExpirationMonth"
runat="server">
<asp:ListItem Value="1">January</asp:ListItem>
<asp:ListItem Value="2">February</asp:ListItem>
<asp:ListItem Value="3">March</asp:ListItem>
<asp:ListItem Value="4">April</asp:ListItem>
<asp:ListItem Value="5">May</asp:ListItem>
<asp:ListItem Value="6">June</asp:ListItem>
<asp:ListItem Value="7">July</asp:ListItem>
<asp:ListItem Value="8">August</asp:ListItem>
<asp:ListItem Value="9">September</asp:ListItem>
<asp:ListItem Value="10">October</asp:ListItem>
<asp:ListItem Value="11">November</asp:ListItem>
<asp:ListItem Value="12">December</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlExpirationYear"
runat="server">
</asp:DropDownList>
</td>
</tr>
</table>
</asp:WizardStep>
</WizardSteps>
</asp:Wizard>
</div>
</form>
</body>
</html>
File: Default.aspx.vb
Partial Class Checkout
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
wizCheckout.ActiveStepIndex = 0
Dim iYear As Integer
For iYear = DateTime.Now.Year To DateTime.Now.Year + 5
ddlExpirationYear.Items.Add(iYear.ToString())
Next
End If
End Sub
Protected Sub wizCheckout_CancelButtonClick(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles wizCheckout.CancelButtonClick
wizCheckout.ActiveStepIndex = 0
txtFirstName.Text = ""
txtLastName.Text = ""
txtEmail.Text = ""
rdoUPSGround.Checked = True
rdoUPS2Day.Checked = False
rdoFedEx.Checked = False
lstCardType.SelectedIndex = 0
txtCardNumber.Text = ""
ddlExpirationMonth.SelectedIndex = 0
ddlExpirationYear.SelectedIndex = 0
End Sub
End Class
how to set up and use a wizard.
<%@ Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Simple Wizard</title>
</head>
<body>
<div id="pageContent">
<form id="form1" runat="server">
<h2>The simplest wizard!</h2>
<asp:wizard ID="Wizard1" runat="server" HeaderText="Sample Wizard" DisplaySideBar="true">
<SideBarStyle BackColor="lightcyan" />
<HeaderStyle ForeColor="Info" />
<wizardsteps>
<asp:wizardstep runat="server" steptype="auto" id="step1">
<h3>First step</h3>
</asp:wizardstep>
<asp:wizardstep runat="server" steptype="auto" id="step2">
<h3>Second step</h3>
</asp:wizardstep>
<asp:wizardstep runat="server" steptype="auto" id="finish">
<h3>Final step</h3>
</asp:wizardstep>
</wizardsteps>
</asp:wizard>
</form>
</div>
</body>
</html>
Use WizardStep
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Wizard ID="Wizard1" runat="server">
<WizardSteps>
<asp:WizardStep ID="stpWakeUp" runat="server" Title="Step 1">
<h2>Wake Up</h2>
</asp:WizardStep>
<asp:WizardStep ID="stpShower" runat="server" Title="Step 2">
<h2>Shower</h2>
</asp:WizardStep>
<asp:WizardStep ID="stpTakeMeds" runat="server" Title="Step 3">
<h2>Take Meds</h2>
</asp:WizardStep>
<asp:WizardStep ID="stpBrushTeeth" runat="server" Title="Step 4">
<h2>Brush Teeth</h2>
</asp:WizardStep>
<asp:WizardStep ID="stpGetDressed" runat="server" Title="Step 5 ">
<h2>Get Dressed</h2>
</asp:WizardStep>
<asp:WizardStep ID="stpEatBreakfast" runat="server" Title="Step 6">
<h2>Eat Breakfast</h2>
</asp:WizardStep>
<asp:WizardStep ID="stpFinish" runat="server" Title="Step 7">
<h2>Finish</h2>
</asp:WizardStep>
</WizardSteps>
</asp:Wizard>
</div>
</form>
</body>
</html>
Wizard ActiveStepIndex
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="WizardForm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Wizard Form</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0" BackColor="#EFF3FB" BorderColor="#B5C7DE" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" Height="265px" Width="406px" OnActiveStepChanged="Wizard1_ActiveStepChanged" DisplaySideBar="False" >
<WizardSteps>
<asp:WizardStep runat="server" Title="Enter text in text box">
<asp:Label ID="Label1" runat="server" Text="Step 1"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Text="Your Dog"s Name is:"></asp:Label>
<asp:TextBox ID="DogName" runat="server"></asp:TextBox>
</asp:WizardStep>
<asp:WizardStep runat="server" Title="Select from drop-down list">
<asp:Label ID="Label3" runat="server" Text="Step 2"></asp:Label>
<br />
<asp:Label ID="Label4" runat="server" Text="Your Favorite Color:"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
</asp:DropDownList>
</asp:WizardStep>
<asp:WizardStep runat="server" Title="Select or clear a check box">
<asp:Label ID="Label5" runat="server" Text="Step 3"></asp:Label>
<br />
<asp:CheckBox ID="CheckBox1" runat="server" Text="I am allergic to cats" />
</asp:WizardStep>
<asp:WizardStep runat="server" Title="Finish">
<asp:Label ID="Label6" runat="server" Text="Step 4"></asp:Label>
<br />
<asp:Label ID="FinishLabel" runat="server"></asp:Label>
</asp:WizardStep>
</WizardSteps>
<StepStyle Font-Size="0.8em" ForeColor="#333333" />
<SideBarStyle BackColor="Yellow" Font-Size="0.9em" VerticalAlign="Top" />
<SideBarButtonStyle BackColor="Yellow" Font-Names="Verdana" ForeColor="White" />
<HeaderStyle BackColor="#284E98"
BorderColor="#EFF3FB"
BorderStyle="Solid"
BorderWidth="2px"
Font-Bold="True"
Font-Size="0.9em"
ForeColor="White"
HorizontalAlign="Center" />
<NavigationButtonStyle BackColor="White"
BorderColor="Yellow"
BorderStyle="Solid"
BorderWidth="1px"
Font-Names="Verdana"
Font-Size="0.8em"
ForeColor="#284E98" />
</asp:Wizard>
</div>
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class WizardForm : System.Web.UI.Page
{
protected void Wizard1_ActiveStepChanged(object sender, EventArgs e)
{
if ( this.Wizard1.ActiveStepIndex==3 )
{
this.FinishLabel.Text =
"Your Dog"s Name is " +
this.DogName.Text + "<br />";
this.FinishLabel.Text +=
"Your favorite color is " +
this.DropDownList1.SelectedItem.Text +
"<br />";
if (this.CheckBox1.Checked == true)
{
this.FinishLabel.Text +=
"And you are allergic to cats.";
}
else
{
this.FinishLabel.Text +=
"And you are <b>not</b> allergic to cats.";
}
}
}
}
Wizard Demo
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>Wizard Demo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0" HeaderText="Menu Selector"
Height="200px" Width="400px" OnFinishButtonClick="Wizard1_FinishButtonClick" OnNextButtonClick="Wizard1_NextButtonClick">
<WizardSteps>
<asp:WizardStep runat="server" Title="Step 1">
What is your eating preference?<br />
<br />
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem>Meat Eater</asp:ListItem>
<asp:ListItem>Vegetarian</asp:ListItem>
</asp:RadioButtonList>
</asp:WizardStep>
<asp:WizardStep runat="server" Title="Step 2">
Please select main course:<br />
<br />
<asp:RadioButtonList ID="RadioButtonList2" runat="server">
<asp:ListItem>Chicken</asp:ListItem>
<asp:ListItem>Fish</asp:ListItem>
<asp:ListItem>Steak</asp:ListItem>
</asp:RadioButtonList>
</asp:WizardStep>
<asp:WizardStep runat="server" Title="Step 3">
Please select main course:<br />
<br />
<asp:RadioButtonList ID="RadioButtonList3" runat="server">
<asp:ListItem>Bread</asp:ListItem>
<asp:ListItem>Salad</asp:ListItem>
<asp:ListItem>Veggie Tray</asp:ListItem>
</asp:RadioButtonList>
</asp:WizardStep>
<asp:WizardStep runat="server" Title="Step 4">
Please select beverage:<br />
<br />
<asp:RadioButtonList ID="RadioButtonList4" runat="server">
<asp:ListItem>Coffee</asp:ListItem>
<asp:ListItem>Water</asp:ListItem>
<asp:ListItem>Wine</asp:ListItem>
</asp:RadioButtonList>
</asp:WizardStep>
</WizardSteps>
</asp:Wizard>
</div>
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
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;
}
}
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);
}
}
}
Wizard finish button click event
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Default_aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0" Width="308px">
<WizardSteps>
<asp:WizardStep runat="server" Title="Step 1">
Enter your name:<br />
First Name
<asp:TextBox runat="server" ID="txtFirstName"></asp:TextBox>
<br />
Last Name
<asp:TextBox runat="server" ID="txtLastName"></asp:TextBox>
<br />
</asp:WizardStep>
<asp:WizardStep runat="server" Title="Step 2">
Birthday:<br />
<asp:Calendar runat="server" ID="Calendar1"></asp:Calendar>
</asp:WizardStep>
<asp:WizardStep runat="server" Title="Step 3">
Thank you for registering with us.</asp:WizardStep>
</WizardSteps>
</asp:Wizard>
</div>
<br />
<br />
</form>
</body>
</html>
File: Default.aspx.vb
Partial Class Default_aspx
Inherits System.Web.UI.Page
Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) _
Handles Wizard1.FinishButtonClick
Response.Write("You have registered as " & _
txtFirstName.Text & _
txtLastName.Text & "<br/>")
Response.Write("Birthday " & _
Calendar1.SelectedDate)
Wizard1.Visible = False
End Sub
End Class
Wizard history
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Wizard Demo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Wizard Demo</h1>
<asp:Wizard ID="wzrdMorning" runat="server"
DisplayCancelButton="True"
OnCancelButtonClick="wzrdMorning_CancelButtonClick"
OnActiveStepChanged="wzrdMorning_ActiveStepChanged"
OnFinishButtonClick="Button_Click"
OnNextButtonClick="Button_Click"
OnPreviousButtonClick="Button_Click"
OnSideBarButtonClick="Button_Click"
BackColor="#E6E2D8"
BorderColor="#999999"
BorderWidth="1px"
Font-Names="Verdana" Font-Size="0.8em" >
<WizardSteps>
<asp:WizardStep ID="stpWakeUp" runat="server"
Title="Step 1"
StepType="Start">
<h2>Wake Up</h2>
Rise and shine sleepy head.
</asp:WizardStep>
<asp:WizardStep ID="stpShower" runat="server"
Title="Step 2">
<h2>Shower</h2>
Make it cold!
</asp:WizardStep>
<asp:WizardStep ID="stpTakeMeds" runat="server"
Title="Step 3"
AllowReturn="False">
<h2>Take Medicine</h2>
Only do this once.
</asp:WizardStep>
<asp:WizardStep ID="stpBrushTeeth" runat="server"
Title="Step 4">
<h2>Brush Teeth</h2>
Don"t forget to floss.
</asp:WizardStep>
<asp:WizardStep ID="stpGetDressed" runat="server"
Title="Step 5">
<h2>Get Dressed</h2>
Got to look good.
</asp:WizardStep>
<asp:WizardStep ID="stpEatBreakfast" runat="server"
Title="Step 6">
<h2>Eat Breakfast</h2>
The most important meal of the day.
</asp:WizardStep>
<asp:WizardStep ID="stpFinish" runat="server"
Title="Step 7"
StepType="Finish">
<h2>Out the Door</h2>
Meet the world!
</asp:WizardStep>
<asp:WizardStep ID="stpComplete" runat="server"
StepType="Complete"
Title="Complete">
<h2>Complete!</h2>
Your morning routine is now complete.
</asp:WizardStep>
</WizardSteps>
<StepStyle BackColor="#F7F6F3"
BorderColor="#E6E2D8"
BorderStyle="Solid"
BorderWidth="2px" />
<SideBarStyle BackColor="#1C5E55"
Font-Size="0.9em"
VerticalAlign="Top" />
<NavigationButtonStyle BackColor="White"
BorderColor="#C5BBAF"
BorderStyle="Solid"
BorderWidth="1px"
Font-Names="Verdana"
Font-Size="0.8em"
ForeColor="#1C5E55" />
<SideBarButtonStyle ForeColor="White" />
<HeaderStyle BackColor="#666666"
BorderColor="#E6E2D8"
BorderStyle="Solid"
BorderWidth="2px"
Font-Bold="True"
Font-Size="0.9em"
ForeColor="White"
HorizontalAlign="Center" />
</asp:Wizard>
<br />
Select a step:
<asp:DropDownList ID="DropDownList1"
runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
</asp:DropDownList>
<br />
<br />
Active Step:
<asp:Label ID="lblActiveStep" runat="server" />
<br />
ActiveStepIndex:
<asp:Label ID="lblActiveStepIndex" runat="server" />
<br />
StepType:
<asp:Label ID="lblStepType" runat="server" />
<br />
Button Info:
<asp:Label ID="lblButtonInfo" runat="server" />
<br />
<br />
<u>History</u>
<asp:Label ID="lblHistory" runat="server" />
</div>
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
protected void wzrdMorning_ActiveStepChanged(object sender, EventArgs e)
{
lblActiveStep.Text = wzrdMorning.ActiveStep.Title;
lblActiveStepIndex.Text = wzrdMorning.ActiveStepIndex.ToString();
lblStepType.Text = wzrdMorning.ActiveStep.StepType.ToString();
ICollection steps = wzrdMorning.GetHistory();
string str = "";
foreach (WizardStep step in steps)
{
str += step.Title + "<br/>";
}
lblHistory.Text = str;
}
protected void Button_Click(object sender, WizardNavigationEventArgs e){
string str = "Current Index: " +
e.CurrentStepIndex.ToString() +
". Next Step: " + e.NextStepIndex.ToString();
lblButtonInfo.Text = str;
}
protected void wzrdMorning_CancelButtonClick(object sender, EventArgs e){
lblActiveStep.Text = "";
lblActiveStepIndex.Text = "";
lblStepType.Text = "";
lblButtonInfo.Text = "Canceled";
wzrdMorning.Visible = false;
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) {
DropDownList ddl = (DropDownList)sender;
int index = ddl.SelectedIndex;
WizardStepBase step = wzrdMorning.WizardSteps[index];
wzrdMorning.MoveTo(step);
}
}
Wizard template
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="WizardTemplates" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Wizard ID="Wizard1"
runat="server"
Width="467px"
BackColor="#EFF3FB"
BorderColor="#B5C7DE"
BorderWidth="1px"
Font-Names="Verdana"
CellPadding="5"
ActiveStepIndex="0"
Font-Size="Small"
OnFinishButtonClick="Wizard1_FinishButtonClick">
<WizardSteps>
<asp:WizardStep ID="WizardStep1" runat="server" Title="Personal">
<h3>Personal Profile</h3>
Preferred Programming Language:
<asp:DropDownList ID="lstLanguage" runat="server">
<asp:ListItem>C#</asp:ListItem>
<asp:ListItem>VB .NET</asp:ListItem>
<asp:ListItem>J#</asp:ListItem>
<asp:ListItem>Java</asp:ListItem>
<asp:ListItem>C++</asp:ListItem>
<asp:ListItem>C</asp:ListItem>
</asp:DropDownList>
<br />
</asp:WizardStep>
<asp:WizardStep ID="WizardStep2" runat="server" Title="Company">
<h3>Comany Profile</h3>
Number of Employees: <asp:TextBox ID="txtEmpCount" runat="server"></asp:TextBox>
Number of Locations: <asp:TextBox ID="txtLocCount" runat="server"></asp:TextBox>
</asp:WizardStep>
<asp:WizardStep ID="WizardStep3" runat="server" Title="Software">
<h3>Software Profile</h3>
Licenses Required:
<asp:CheckBoxList ID="lstTools" runat="server">
<asp:ListItem>Visual Studio</asp:ListItem>
<asp:ListItem>Office</asp:ListItem>
<asp:ListItem>Windows 2003 Server</asp:ListItem>
<asp:ListItem>SQL Server 2005</asp:ListItem>
<asp:ListItem>BizTalk 2004</asp:ListItem>
</asp:CheckBoxList>
</asp:WizardStep>
<asp:WizardStep ID="Complete" runat="server" Title="Complete " StepType="Complete">
Summary:<asp:Label ID="lblSummary" runat="server" Text="Label"></asp:Label>
</asp:WizardStep>
</WizardSteps>
<SideBarStyle VerticalAlign="Top" />
<HeaderTemplate>
<i>Header Template</i> -
<b><%= Wizard1.ActiveStep.Title %></b>
</HeaderTemplate>
<StepNavigationTemplate>
<i>StepNavigationTemplate</i><br />
<asp:Button ID="StepPreviousButton" runat="server" CausesValidation="False" CommandName="MovePrevious"
Text="Previous" />
<asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext" Text="Next" />
</StepNavigationTemplate>
<StartNavigationTemplate>
<i>StartNavigationTemplate</i><br />
<asp:Button ID="StartNextButton" runat="server" CommandName="MoveNext" Text="Next" />
</StartNavigationTemplate>
<FinishNavigationTemplate>
<i>FinishNavigationTemplate</i><br />
<asp:Button ID="FinishPreviousButton" runat="server" CausesValidation="False" CommandName="MovePrevious"
Text="Previous" />
<asp:Button ID="FinishButton" runat="server" CommandName="MoveComplete" Text="Finish" />
</FinishNavigationTemplate>
</asp:Wizard>
</div>
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
public partial class WizardTemplates : System.Web.UI.Page
{
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.Append("You chose: <br />");
sb.Append("Programming Language: ");
sb.Append(lstLanguage.Text);
sb.Append("<br />Total Employees: ");
sb.Append(txtEmpCount.Text);
sb.Append("<br />Total Locations: ");
sb.Append(txtLocCount.Text);
sb.Append("<br />Licenses Required: ");
foreach (ListItem item in lstTools.Items)
{
if (item.Selected)
{
sb.Append(item.Text);
sb.Append(" ");
}
}
lblSummary.Text = sb.ToString();
}
}