SIGN UP MEMBER LOGIN:    
ARTICLE

Tab Container in ASP.NET

Posted by Krishna Garad Articles | AJAX in C# January 19, 2012
In this article we will see how to use an Ajax TabContainer in ASP.NET.
Reader Level:

Introduction

In this article we will see how to use an Ajax TabContainer in ASP.NET. As you all know, creating a tab in an ASP.Net web application is something critical. To create a control like a tab in our ASP.Net application we can use a muliview control with various views but again same keeping some buttons to change the ActiveViewIndex of multiview control. This causes a postback to the server and for changing the view we only have to wait until the page reloads.

You all know in Windows applications we have a tabcontainer control which is collection of tabpages but in ASP.Net that kind of control is not available but using Ajax we can create a tabcontainer control. So let's start using Ajax TabContainer control.

Step 1:

Create a new website and add a reference to AjaxControlToolkit.

Step 2:

Register the tagprefix references to AjaxControlToolkit like below.

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

Step 3:

Now first we need to keep one scriptmanger control on our ASP.Net web page so keep it like given below.

<asp:ScriptManager ID="ScriptManager1" runat="server">

        </asp:ScriptManager>

Step 4:

Now it's time to put the tabcontainer control of Ajax but remember the Ajax TabContainer control doesn't have TabPages where we can add TabPages like in Windows form. In the Ajax TabContainer we have TabPanels like tab pages in a Windows form. So add a TabContainer on the page like below.

<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0"
            Width="600">
  </cc1:TabContainer>

Above we created an empty tabcontainer control that does not have a tabpanel in it. Next we will create tabpages for our tabcontainer.

Step5:

Now create tabpanels for our tabcontainer control like below:

<cc1:TabPanel ID="TabPanel1" runat="server">
 <HeaderTemplate></HeaderTemplate>
 <ContentTemplate></ContentTemplate>
 </cc1:TabPanel>

In the above line you are seen there are two templates; one is a HeaderTemplate and another is a ContentTemplate. In the HeaderTamplate you can provide the header for a TabPanel and in the ContentTemplate you can put any another controls in it.

<cc1:TabPanel ID="TabPanel1" runat="server">
                <HeaderTemplate>
                   Tab Panel One
                </HeaderTemplate>
                <ContentTemplate>
                    <asp:Image ID="Image1" runat="server" Height="140px" ImageUrl="~/dg1.gif"
                        Width="138px" />
                    Tab Panel1
                </ContentTemplate>
            </cc1:TabPanel>

In this way you can create a TabContainer and TabPanels in ASP.Net as well; you can use your own styles for the TabContainer as well as TabPanels. The following is the complete source for a tabcontainer.

<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0"
            Width="600">
            <cc1:TabPanel ID="TabPanel1" runat="server">
                <HeaderTemplate>
                   Tab Panel One
                  </HeaderTemplate>
                <ContentTemplate>
                    <asp:Image ID="Image1" runat="server" Height="140px" ImageUrl="~/dg1.gif"
                        Width="138px" />
                    Tab Panel1
                </ContentTemplate>
            </cc1:TabPanel>
            <cc1:TabPanel ID="TabPanel2" runat="server">
                <HeaderTemplate>
                  Tab Panel Two
                 </HeaderTemplate>
                <ContentTemplate>
                    <asp:RadioButtonList ID="RadioButtonList1" runat="server">
                        <asp:ListItem>Items</asp:ListItem>
                        <asp:ListItem>Items</asp:ListItem>
                        <asp:ListItem>Items</asp:ListItem>
                        <asp:ListItem>Itens</asp:ListItem>
                        <asp:ListItem>Items</asp:ListItem>
                       <asp:ListItem>Items</asp:ListItem>
                    </asp:RadioButtonList>
                    <asp:Image ID="Image3" runat="server" Height="89px" ImageUrl="~/dg2.gif"
                        Width="122px" />
                    Tab Panel2
                </ContentTemplate>
            </cc1:TabPanel>
            <cc1:TabPanel ID="TabPanel3" runat="server">
                <HeaderTemplate>
                  Tab Panel Three
                 </HeaderTemplate>
                <ContentTemplate>
                    <asp:Image ID="Image2" runat="server" Height="151px" ImageUrl="~/dg3.gif"
                        Width="106px" />
                    Tab panel 3
                </ContentTemplate>
            </cc1:TabPanel>
       </cc1:TabContainer>

Conclusion:

In this way you can create the tabcontainer control in ASP.Net and keep more of the content in just one page.

Login to add your contents and source code to this article
share this article :
post comment
 

okay!!! then what should be done to correct it as i am beginner of asp.net. don't know much about it.google chrome browser is used me.

Posted by Jaspreet Kaur Apr 24, 2012

It might be cross browser issue with your stylesheet. Check it

Posted by Krishna Garad Apr 24, 2012

sir,I have used this code in my project. but it is not shown when i debug it. I have done visibility of tab container to true but still it is not shown. kindly tell me what to do thanks

Posted by Jaspreet Kaur Apr 23, 2012

very nice article thanks.

Posted by Jaspreet Kaur Apr 23, 2012

Thanks for your article - but really - give us some grown up stuff. Give us a tabcontainer with tabs on the right side, tabs with customable style and size, and tabs with images. Looking foreward to see your dev

Posted by freddy andersen Feb 12, 2012
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Nevron Gauge for SharePoint
Become a Sponsor