Click here to Skip to main content
6,629,377 members and growing! (21,125 online)
Email Password   helpLost your password?
Web Development » Ajax and Atlas » General     Beginner License: The Code Project Open License (CPOL)

Using ASP.NET AJAX TAB Control

By saanj

Using ASP.NET AJAX TAB Control
C#, ASP.NET, ADO.NET, Ajax
Version:2 (See All)
Posted:28 Jul 2008
Views:40,107
Bookmarked:22 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
8 votes for this article.
Popularity: 3.25 Rating: 3.60 out of 5

1
2 votes, 25.0%
2
2 votes, 25.0%
3
1 vote, 12.5%
4
3 votes, 37.5%
5

Introduction

ASP.NET AJAX Toolkit is one the most useful and free tools available today to make ASP.NET Rich UI Interactive applications. In this article, I am going to discuss one of the very important tools available in this toolkit. It is the TabContainer control. Once you referred the AJAXControlToolkit.dll in your project, you can add all AJAXControl Toolkits to the toolbox in your Visual Studio .NET IDE. You can download the AJAXControlToolkit.dll from the following location:

Or please refer to the following article:

TabContainer control is a very simple to use tab control like what we are used to in our Windows applications. Just place the required controls in different tab panels (just like Windows forms) and trap the ActiveTabChanged event and do all the necessary actions which suit your application requirements.

Background

I have seen many people (I am also one of them) are used to manually creating individual panels and images to create tabs in ASP.NET applications. Those are actually not tabs, but created and shown in such a way that users can visualize and get a feeling that they are actually working with tabs. I actually worked in these kinds of applications and please believe me, it's not so easy to maintain and definitely the lines of code get increased. AJAXControlToolikit really helps in this context.

Using the Example

I am quite sure that nobody is convinced without actually seeing the code. In this code demonstration, I am using a TabContainer control which has three tabs that I added by clicking on Add Tab Panel option available in the property panel. Now, three different grid views are added in three different tabs and what I am trying to do is on ActiveTabChanged event of each tab dependant grid views will be populated. You can download the code which is provided with this article. Postback can be avoided by simply setting...

AutoPostBack = "False" 

... in ActiveTabChanged event of the Tab Container. By default it is set to true.

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 TabControl : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
        if (!IsPostBack) 
        { 
            TabContainer1_ActiveTabChanged(TabContainer1, null); 
        } 
    } 

    protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e) 
    { 
        DataTable dTable_rgstrtn = null; 
        DataTable dTable_btch = null; 
        DataTable dTable_crs = null; 
        
        try 
        { 
            if (TabContainer1.ActiveTabIndex == 0) 
            { 
                dTable_rgstrtn = new DataTable();
                        dTable_rgstrtn.Columns.Add("stdnt_cd"); 
                dTable_rgstrtn.Columns.Add("rgstrtn_cd");
                        dTable_rgstrtn.Columns.Add("sbjct_chsn"); 
                dTable_rgstrtn.Columns.Add("stdnt_stts");
                        
                dTable_rgstrtn.Rows.Add(dTable_rgstrtn.NewRow()); 
                
                dTable_rgstrtn.Rows[0]["stdnt_cd"] = "S0080032003023"; 
                dTable_rgstrtn.Rows[0]["rgstrtn_cd"] = "R0080032003023"; 
                dTable_rgstrtn.Rows[0]["sbjct_chsn"] = "ASP.NET 3.0, SQL 2005, XML"; 
                dTable_rgstrtn.Rows[0]["stdnt_stts"] = "VALID";
            
                GridView1.DataSource = dTable_rgstrtn; 
                GridView1.DataBind(); 
                GridView1.Visible = true; 
            } 
        
            if (TabContainer1.ActiveTabIndex == 1) 
            { 
                dTable_btch = new DataTable();
    
                        dTable_btch.Columns.Add("btch_cd"); 
                dTable_btch.Columns.Add("smstr_cd"); 
                dTable_btch.Columns.Add("smstr_vrsn");
                        dTable_btch.Columns.Add("mx_nmbr_stdnt"); 
                
                dTable_btch.Rows.Add(dTable_btch.NewRow());
                        
                dTable_btch.Rows[0]["btch_cd"] = "B0001"; 
                dTable_btch.Rows[0]["smstr_cd"] = "SM100";
                        dTable_btch.Rows[0]["smstr_vrsn"] = "1.00"; 
                dTable_btch.Rows[0]["mx_nmbr_stdnt"] = "20"; 
                
                GridView2.DataSource = dTable_btch; 
                GridView2.DataBind(); 
                GridView2.Visible = true; 
            } 
            
            if (TabContainer1.ActiveTabIndex == 2) 
            { 
                dTable_crs = new DataTable();
                    
                dTable_crs.Columns.Add("crs_ttl"); 
                dTable_crs.Columns.Add("crs_drtn"); 
                dTable_crs.Columns.Add("smrt_crd_rqrd");
                        
                dTable_crs.Rows.Add(dTable_crs.NewRow()); 
                
                dTable_crs.Rows[0]["crs_ttl"] = "Introducing ASP.NET 3.5"; 
                dTable_crs.Rows[0]["crs_drtn"] = "48 Hrs"; 
                dTable_crs.Rows[0]["smrt_crd_rqrd"] = "Yes"; 
                
                GridView3.DataSource = dTable_crs; 
                GridView3.DataBind(); 
                GridView3.Visible = true; } 
            } 
            
            catch 
            { 
                throw; 
            } 
            finally 
            { 
                dTable_btch = null; 
                dTable_crs = null; 
                dTable_rgstrtn = null; 
            } 
        } 
    }

As the code suggests, there is no complicated logic or handling needed to implement the tab control. If different tabs in the tab panel don't contain any dynamic data or validation, then it is preferred to set the AutoPostBack property to false. This will make the tab operations much more faster. By using AJAX Update Progess, you can make the tab operations much more user interactive.

AJAXTabControl/Sc2.JPG

History

  • 29th July, 2008: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

saanj


Member
A .NET Lover romancing in Gurgaon, India.

Hometown is in Kolkata, India.

Working in ASP.NET, C#.NET, AJAX, XML, SQL Server, SQL Server Reporting Services, JavaScript, MOSS 2007.

Enjoys Cricket, National & World Music.

Favourite band include Silkroute, Euphoria, Coldplay, Oasis, Linkin Park, MLTR
Occupation: Software Developer
Location: India India

Other popular Ajax and Atlas articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 22 of 22 (Total in Forum: 22) (Refresh)FirstPrevNext
GeneralDoes this work with MasterPages Pinmemberjb19612:54 21 Aug '09  
GeneralAjax tab Control as Menu PinmemberNazneen.Insignia21:28 16 Aug '09  
QuestionSetting the Default Tab Pinmemberchana gibber5:27 5 Aug '09  
GeneralNot working for me Pinmembervenkat86_ece23:05 17 Jun '09  
GeneralRe: Not working for me Pinmembersaanj0:36 18 Jun '09  
GeneralRe: Not working for me Pinmembervenkat86_ece4:27 18 Jun '09  
GeneralRe: Not working for me Pinmembersaanj4:49 18 Jun '09  
GeneralRe: Not working for me Pinmembervenkat86_ece1:43 19 Jun '09  
GeneralRe: Not working for me Pinmembersaanj2:55 19 Jun '09  
GeneralRe: Not working for me Pinmembervenkat86_ece3:17 19 Jun '09  
GeneralRe: Not working for me Pinmembervenkat86_ece21:40 23 Jun '09  
QuestionHow to load different aspx pages in tabs Pinmembermian ghous12:10 22 May '09  
AnswerRe: How to load different aspx pages in tabs Pinmembersaanj0:35 18 Jun '09  
GeneralAjax tab PinmemberJackuline2:30 28 Apr '09  
GeneralRe: Ajax tab Pinmembersaanj8:12 28 Apr '09  
GeneralTab Pictures Pinmemberkhaliltalal2:30 19 Mar '09  
GeneralRe: Tab Pictures Pinmembersaanj8:30 28 Apr '09  
GeneralRe: Tab Pictures Pinmembersaanj8:33 28 Apr '09  
Generalajax tab panel control PinmemberManikyamba1:00 5 Dec '08  
AnswerRe: ajax tab panel control Pinmembersaanj4:46 5 Dec '08  
GeneralArticle is good but for me not working Pinmembertestarun1:21 6 Aug '08  
AnswerRe: Article is good but for me not working Pinmembersaanj0:29 31 Oct '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 28 Jul 2008
Editor: Deeksha Shenoy
Copyright 2008 by saanj
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project