Multi Step Form In ASP.NET

This tutorial is for the beginner, who wants to create Tab structure or multi step form in ASP.NET. In this article, we will see how we can create Tab view in ASP.NET. We will use default Multiview control for it.

Thus, let's start.
 
Multiview will be used to display the content on the tap of Tab.  

To show tab on the top, we will use Menu control. Thus, let's go and Add menu control from toolbox. I have given the Horizontal orientation, so that Tab will display horizontally.  
  1. <asp:Menu  
  2.                ID="menuTabs"  
  3.                Orientation="Horizontal"  
  4.                Width="100%"  
  5.                runat="server">  
  6.                <Items>  
  7.                    <asp:MenuItem Text="Employee Info" Value="0" Selected="true"/>  
  8.                    <asp:MenuItem Text="Contact Info" Value="1" />  
  9.                    <asp:MenuItem Text="Salary Info" Value="2" />  
  10.                </Items>  
  11.  </asp:Menu>  
To display the content for each tab, we will use Multiview control. I have given a property Selected="true" for Employee Info, so that when a page is launched, it will display the content of Employee Info. 
  1. <asp:MultiView ID="multiviewEmployee"  
  2.                           runat="server" ActiveViewIndex="0">  
  3.   
  4. </asp:MultiView>  
Next step is to add view inside Multiview. As I have three menu items, I need to add three views inside Multiview.
  1. <asp:MultiView ID="multiviewEmployee"  
  2.                            runat="server" ActiveViewIndex="0">  
  3.                   <asp:View runat="server">  
  4.                     <div>  
  5.                         <%--To do--%>  
  6.                     </div>  
  7.                   </asp:View>  
  8.                    <asp:View runat="server">  
  9.                     <div>  
  10.                         <%--To do--%>  
  11.                     </div>  
  12.                   </asp:View>  
  13.                    <asp:View runat="server">  
  14.                     <div>  
  15.                         <%--To do--%>  
  16.                     </div>  
  17.                   </asp:View>  
  18. </asp:MultiView>   
ActiveViewIndex= "0" will display first view after page is launched. Now, we will open corresponding view, when it is clicked on menu items. For it, we need to handle OnMenuItemClick event of Menu control. Hence, add it in your code and it will look, as mentioned below. 
  1. <asp:Menu  
  2.       ID="menuTabs"  
  3.       Orientation="Horizontal"  
  4.       Width="100%"  
  5.       runat="server"  
  6.       OnMenuItemClick="menuTabs_MenuItemClick">  
  7.       <Items>  
  8.           <asp:MenuItem Text="Employee Info" Value="0" Selected="true"/>  
  9.           <asp:MenuItem Text="Contact Info" Value="1" />  
  10.           <asp:MenuItem Text="Salary Info" Value="2" />  
  11.       </Items>  
  12.   </asp:Menu>  
In CS page, assign the value of menu item to multiview . 
  1. protected void menuTabs_MenuItemClick(object sender, MenuEventArgs e)  
  2.         {  
  3.             Menu menuTabs = sender as Menu;  
  4.             MultiView multiTabs = this.FindControl("multiviewEmployee"as MultiView;  
  5.             multiTabs.ActiveViewIndex = Int32.Parse(menuTabs.SelectedValue);  
  6.               
  7.         }  
Now, it's none. Your tab structure is ready. Full code for ASPX is mentioned below. 
  1. <html xmlns="http://www.w3.org/1999/xhtml">  
  2. <head runat="server">  
  3.     <title></title>  
  4.     <style>  
  5.         .viewCSS {  
  6.             border: solid 2px black;  
  7.             padding: 20px;  
  8.         }  
  9.  
  10.  
  11.         #menuTabs a.static.selected {  
  12.             border-bottom-color: red;  
  13.             border-bottom-style: solid;  
  14.             border-bottom-width: 3px;  
  15.             color: red;  
  16.         }  
  17.     </style>  
  18. </head>  
  19. <body>  
  20.     <form id="form1" runat="server" style="width: 100%">  
  21.         <div style="width: 100%; margin-left: 20px; margin-top: 50px; margin-right: 20px;">  
  22.   
  23.             <asp:Menu  
  24.                 ID="menuTabs"  
  25.                 Orientation="Horizontal"  
  26.                 Width="100%"  
  27.                 runat="server"  
  28.                 OnMenuItemClick="menuTabs_MenuItemClick">  
  29.                 <Items>  
  30.                     <asp:MenuItem Text="Employee Info" Value="0" Selected="true" />  
  31.                     <asp:MenuItem Text="Contact Info" Value="1" />  
  32.                     <asp:MenuItem Text="Salary Info" Value="2" />  
  33.                 </Items>  
  34.             </asp:Menu>  
  35.             <asp:MultiView ID="multiviewEmployee"  
  36.                 runat="server" ActiveViewIndex="0">  
  37.                 <asp:View runat="server">  
  38.                     <div style="margin-top: 40px;">  
  39.                         <asp:Table runat="server" CssClass="viewCSS">  
  40.                             <asp:TableRow>  
  41.                                 <asp:TableCell>  
  42.                                     <asp:Label runat="server">First Name</asp:Label>  
  43.                                 </asp:TableCell>  
  44.                                 <asp:TableCell>  
  45.                                     <asp:TextBox runat="server"></asp:TextBox>  
  46.                                 </asp:TableCell>  
  47.                             </asp:TableRow>  
  48.                             <asp:TableRow>  
  49.                                 <asp:TableCell>  
  50.                                     <asp:Label runat="server">Last Name</asp:Label>  
  51.                                 </asp:TableCell>  
  52.                                 <asp:TableCell>  
  53.                                     <asp:TextBox runat="server"></asp:TextBox>  
  54.                                 </asp:TableCell>  
  55.                             </asp:TableRow>  
  56.                         </asp:Table>  
  57.                     </div>  
  58.                 </asp:View>  
  59.                 <asp:View runat="server">  
  60.                     <div style="margin-top: 40px;">  
  61.                         <asp:Table runat="server" CssClass="viewCSS">  
  62.                             <asp:TableRow>  
  63.                                 <asp:TableCell>  
  64.                                     <asp:Label runat="server">Address</asp:Label>  
  65.                                 </asp:TableCell>  
  66.                                 <asp:TableCell>  
  67.                                     <asp:TextBox runat="server"></asp:TextBox>  
  68.                                 </asp:TableCell>  
  69.                             </asp:TableRow>  
  70.                             <asp:TableRow>  
  71.                                 <asp:TableCell>  
  72.                                     <asp:Label runat="server">Mobile</asp:Label>  
  73.                                 </asp:TableCell>  
  74.                                 <asp:TableCell>  
  75.                                     <asp:TextBox runat="server"></asp:TextBox>  
  76.                                 </asp:TableCell>  
  77.                             </asp:TableRow>  
  78.                         </asp:Table>  
  79.                     </div>  
  80.                 </asp:View>  
  81.                 <asp:View runat="server">  
  82.                     <div style="margin-top: 40px;">  
  83.                         <asp:Table runat="server" CssClass="viewCSS">  
  84.                             <asp:TableRow>  
  85.                                 <asp:TableCell>  
  86.                                     <asp:Label runat="server">Hire Date</asp:Label>  
  87.                                 </asp:TableCell>  
  88.                                 <asp:TableCell>  
  89.                                     <asp:TextBox runat="server"></asp:TextBox>  
  90.                                 </asp:TableCell>  
  91.                             </asp:TableRow>  
  92.                             <asp:TableRow>  
  93.                                 <asp:TableCell>  
  94.                                     <asp:Label runat="server">Salary</asp:Label>  
  95.                                 </asp:TableCell>  
  96.                                 <asp:TableCell>  
  97.                                     <asp:TextBox runat="server"></asp:TextBox>  
  98.                                 </asp:TableCell>  
  99.                             </asp:TableRow>  
  100.                         </asp:Table>  
  101.                     </div>  
  102.                 </asp:View>  
  103.   
  104.             </asp:MultiView>  
  105.         </div>  
  106.     </form>  
  107. </body>  
  108. </html>  
Hope, you enjoyed the article.