Wizard Control In ASP.NET Using C#

In this tutorial, I’ll show you how to make wizard control in ASP.NET using C#, where we will use wizard control to show some students' information. The control can be very useful when we are dealing with step by step registration forms.

INITIAL CHAMBER

Step 1

Open your Visual Studio 2010 and create an Empty website. Give it a suitable name [wizard_demo].

Step 2

In Solution Explorer, you get your empty website. Add a web form, like this –

For Web Form

wizard_demo (your empty website) -> Right click -> Add New Item -> Web Form. Name it as ->wizard_demo.aspx.

DESIGN CHAMBER

Step 3

Open your wizard_demo.aspx, and drag and drop the wizard control from the toolbox. Inside your wizard, add three wizard steps as – Student Details, Student Course Details, Student Personal Details and Student Summary. Design your .aspx file as shown below.

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>  
  2.   
  3. <!DOCTYPE html>  
  4.   
  5. <html xmlns="http://www.w3.org/1999/xhtml">  
  6. <head runat="server">  
  7.     <title></title>  
  8.     <style type="text/css">  
  9.         .auto-style1 {  
  10.             width: 100%;  
  11.         }  
  12.     </style>  
  13. </head>  
  14. <body>  
  15.     <form id="form1" runat="server">  
  16.     <div>  
  17.         <asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0" BackColor="#FFFBD6" BorderColor="#FFDFAD" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" Height="210px" OnNextButtonClick="Wizard1_NextButtonClick" Width="496px">  
  18.             <HeaderStyle BackColor="#FFCC66" BorderColor="#FFFBD6" BorderStyle="Solid" BorderWidth="2px" Font-Bold="True" Font-Size="0.9em" ForeColor="#333333" HorizontalAlign="Center" />  
  19.             <NavigationButtonStyle BackColor="White" BorderColor="#CC9966" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#990000" />  
  20.             <SideBarButtonStyle ForeColor="White" />  
  21.             <SideBarStyle BackColor="#990000" Font-Size="0.9em" VerticalAlign="Top" />  
  22.             <WizardSteps>  
  23.                 <asp:WizardStep ID="WizardStep1" runat="server" Title="Student Details">  
  24.                     <table style="width: 100%;">  
  25.                         <tr>  
  26.                             <td><strong>Student Details</strong></td>  
  27.                               
  28.                         </tr>  
  29.                         <tr>  
  30.                             <td>Student FirstName</td>  
  31.                             <td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>  
  32.                             <td></td>  
  33.                         </tr>  
  34.                         <tr>  
  35.                             <td>Student LastName</td>  
  36.                             <td><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>  
  37.                             <td> </td>  
  38.                         </tr>  
  39.                     </table>  
  40.   
  41.   
  42.                 </asp:WizardStep>  
  43.                 <asp:WizardStep ID="WizardStep2" runat="server" Title="Student Course Details">  
  44.                      <table style="width: 100%;">  
  45.                     <tr>  
  46.                         <td><strong>Student Course Detail</strong></td>  
  47.                          
  48.                     </tr>  
  49.                     <tr>  
  50.                         <td>Student Course</td>  
  51.                         <td><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td>  
  52.                          
  53.                     </tr>  
  54.                     <tr>  
  55.                         <td>Student Branch</td>  
  56.                         <td><asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></td>  
  57.                           
  58.                     </tr>  
  59.                 </table>  
  60.   
  61.                 </asp:WizardStep>  
  62.                  <asp:WizardStep ID="WizardStep3" runat="server" Title="Student Personal Details">  
  63.                 <table style="width: 100%;">  
  64.                     <tr>  
  65.                         <td><strong>Student Personal Detail</strong></td>  
  66.                         
  67.                     </tr>  
  68.                     <tr>  
  69.                         <td>Student EmailId</td>  
  70.                         <td><asp:TextBox ID="TextBox5" runat="server"></asp:TextBox></td>  
  71.                           
  72.                     </tr>  
  73.                     <tr>  
  74.                         <td>Student City</td>  
  75.                         <td><asp:TextBox ID="TextBox6" runat="server"></asp:TextBox></td>  
  76.                          
  77.                     </tr>  
  78.                     <tr>  
  79.                         <td>Student State</td>  
  80.                         <td><asp:TextBox ID="TextBox7" runat="server"></asp:TextBox></td>  
  81.                          
  82.                     </tr>  
  83.                 </table>  
  84.   
  85.             </asp:WizardStep>  
  86.   
  87.                  <asp:WizardStep ID="WizardStep4" runat="server" Title="Student Summary">  
  88.                        
  89.                      <table class="auto-style1">  
  90.                          <tr>  
  91.                              <td><strong>Student Details</strong></td>  
  92.                                
  93.                              <td> </td>  
  94.                                
  95.                          </tr>  
  96.                          <tr>  
  97.                              <td>  
  98.                                  Student FirstName:</td>  
  99.                              <td>  
  100.                                  <asp:Label ID="Label1" runat="server" Text=""></asp:Label>  
  101.                                  </td>  
  102.                              <td> </td>  
  103.                                
  104.                          </tr>  
  105.                          <tr>  
  106.                              <td>Student LastName:</td>  
  107.                                
  108.                              <td>  
  109.                                  <asp:Label ID="Label2" runat="server" Text=""></asp:Label>  
  110.                              </td>  
  111.                                
  112.                          </tr>  
  113.                            
  114.                          <tr>  
  115.                              <td></td>  
  116.                              <td> </td>  
  117.                          </tr>  
  118.                          <tr>  
  119.                              <td><strong>Student Course Details</strong></td>  
  120.                              <td> </td>  
  121.                          </tr>  
  122.                            
  123.                          <tr>  
  124.                              <td>Student Course:</td>  
  125.                              <td>  
  126.                                  <asp:Label ID="Label3" runat="server" Text=""></asp:Label>  
  127.                              </td>  
  128.                          </tr>  
  129.                           <tr>  
  130.                              <td>Student Branch:</td>  
  131.                              <td>  
  132.                                  <asp:Label ID="Label4" runat="server" Text=""></asp:Label>  
  133.                               </td>  
  134.                          </tr>  
  135.                            
  136.                          <tr>  
  137.                              <td> </td>  
  138.                              <td> </td>  
  139.                          </tr>  
  140.                          <tr>  
  141.                              <td><strong>Student Personal Details</strong></td>  
  142.                              <td> </td>  
  143.                          </tr>  
  144.                          <tr>  
  145.                              <td>Student EmailId:</td>  
  146.                              <td>  
  147.                                  <asp:Label ID="Label5" runat="server" Text=""></asp:Label>  
  148.                              </td>  
  149.                          </tr>  
  150.                          <tr>  
  151.                              <td>Student City:</td>  
  152.                              <td>  
  153.                                  <asp:Label ID="Label6" runat="server" Text=""></asp:Label>  
  154.                              </td>  
  155.                          </tr>  
  156.                          <tr>  
  157.                              <td>Student State:</td>  
  158.                              <td>  
  159.                                  <asp:Label ID="Label7" runat="server" Text=""></asp:Label>  
  160.                              </td>  
  161.                          </tr>  
  162.                            
  163.                      </table>  
  164.                 </asp:WizardStep>  
  165.   
  166.                  
  167.             </WizardSteps>  
  168.              
  169.         </asp:Wizard>  
  170.     </div>  
  171.     </form>  
  172. </body>  
  173. </html>   

CODE CHAMBER

Step 5

In here, let’s say after entering every detail, a student wants to view his/her whole information that is entered. For that, we are summarizing everything in the wizard NextButton click.

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7.   
  8. public partial class _Default : System.Web.UI.Page  
  9. {  
  10.     protected void Page_Load(object sender, EventArgs e)  
  11.     {  
  12.         if (!IsPostBack)  
  13.         {  
  14.             refreshdata();  
  15.   
  16.         }  
  17.     }  
  18.   
  19.     private void refreshdata()  
  20.     {  
  21.         Label1.Text = TextBox1.Text;  
  22.         Label2.Text = TextBox2.Text;  
  23.         Label3.Text = TextBox3.Text;  
  24.         Label4.Text = TextBox4.Text;  
  25.         Label5.Text = TextBox5.Text;  
  26.         Label6.Text = TextBox6.Text;  
  27.         Label7.Text = TextBox7.Text;  
  28.   
  29.   
  30.     }  
  31.   
  32.     protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)  
  33.     {  
  34.         if (e.NextStepIndex == 3)  
  35.         {  
  36.             refreshdata();  
  37.         }  
  38.   
  39.     }  
  40. }   

NextstepIndex is the step index where you want to show the details, like Student Details is index = 0, Student Course details is index = 1 and so on. Therefore, the student summary wizard comes in index = 3 that’s why we had taken NextstepIndex as = 3.

OUTPUT

Once the webpage loads, it will show you the wizard in Student Details. Fill the details and press Next.

After this, the wizard loads to the Student Course Details. Press Next, and the control goes to the Student Personal Details.
 
Again, press Next.
 
At last, it will show you the whole Student Information at a glance. I haven’t added any code to the Finish button. You can add code to save these details in your database.

Student Details

Wizard Control In ASP.NET

Student Course Details

Wizard Control In ASP.NET

Student Personal Details

Wizard Control In ASP.NET

Student Summary

Wizard Control In ASP.NET

Hope you like this. Thank you for reading!


Similar Articles