Wizard Control In asp.net csharp-: This is a advance control its definition is a step by step process to perform any task. In this process we can perform any task by clicking next, if we have any mistake in process we can go to back to previous step. Sometime we want to break process in the middle so we have a cancel button to break process in the middle.
How to add wizard control in asp.net csharp page-: Like the other control we can add wizard control by double click in tool box or drag and drop by using mouse. We can write the code here for adding the wizard control . The syntax of writing wizard control
<asp:Wizard ID="Wizard1" runat="server">
<WizardSteps>
<asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1"></asp:WizardStep>
<asp:WizardStep ID="WizardStep2" runat="server" Title="Step 2"></asp:WizardStep>
</WizardSteps>
</asp:Wizard>
Property of Wizard control-: some property are same like id,font, color, size are same the label control,text-box control, etc. There are some other property has been given here
ActiveStepIndex -:The value for this property is the current step in design view.so if you run the web page you will find the current step will rendered on the page. To show the first step in the wizard control you should set the ActiveStepIndex property to 0 in the page load event.
DisplaySideBar-: This property is used to turn on or off the link on the side that is present in the wizard control.You can hide this side bar by setting this property to false. The default setting is true.
DisplayCancelbutton-: If you want give the user the ability to cancel the wizard then set this property to true. In this case the cancel button will be displayed on every wizard step. To handle the click event of the cancel button a manual code addition is required in the CancelButtonClick() event of the wizard control.
Events of wizard control -: There are some event of wizard control the list has been given here
- ActiveStepChanged-: This events is raised when a step is changed within the wizard control.
- SideBarButtonClick-: This event is raised if any link present on side bar is clicked
- PreviousButtonClick-:raised when the previous button is pressed
- NextButtonClick-: raised when the next button is pressed
- FinishButtonClick-: raised when the finish button is pressed
- CancelButtonClick-: raised when the cancel button pressed.
Example of wizard control with radio button and text button
<div>
<asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0" OnNextButtonClick="Wizard1_NextButtonClick">
<WizardSteps>
<asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</asp:WizardStep>
<asp:WizardStep ID="WizardStep2" runat="server" Title="Step 2">
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="gs" />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="gs" />
</asp:WizardStep>
<asp:WizardStep ID="WizardStep3" runat="server" Title="Step 3">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></asp:WizardStep>
</WizardSteps>
</asp:Wizard>
</div>
Now we write the code on default.aspx.cs page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
{
int i, j;
i = int.Parse(TextBox1.Text);
j = int.Parse(TextBox2.Text);
if (Wizard1.ActiveStepIndex == 1)
{
if (RadioButton1.Checked == true)
{
Label1.Text = "total =" + Convert.ToString(i + j);
}
else if (RadioButton2.Checked == true)
{
Label1.Text = "total =" + Convert.ToString(i - j);
}
}
}
}
In this example we can add and subtract data from wizard control.