Click here to Skip to main content
14,024,060 members
Click here to Skip to main content
Add your own
alternative version


41 bookmarked
Posted 25 Apr 2008
Licenced CPOL

Auto Resize TabContainer

, 25 Apr 2008
Rate this:
Please Sign up or sign in to vote.
Automatically resize a TabContainer or TabPanel.


While dynamically loading TabPanels into a TabContainer, I noticed that the border on the TabContainer wouldn't automatically resize itself. I also couldn't find anything on the web about it. Eventually, I set it to a certain height and hoped that no one would notice, but they did. The content ran on down the page, and the TabContainer border height was stuck at 400. I used this code to fix that problem.

Hope it works for you!

After creating this write-up, I also found that creating a panel (the equivalent of a div tag, not a tab panel), setting the height to 100%, and wrapping all the controls in the tab with the panel works just as well - no JavaScript is needed when using this method.

I will leave this up in case someone needs to figure out how to resize a tab in JavaScript for some reason.

Using the code

Use the OnClientActiveTabChanged property to call some JavaScript.

<ajaxToolkit:TabContainer ID="tabContainer" runat="server" 

                          OnClientActiveTabChanged="doSizeUp" />

Then use this JavaScript function to resize:

function doSizeUp(){
    //get the tabContainer for later reference
    var tc = document.getElementById("<%=tabContainer.ClientId%>");
    //get the index of the tab you just clicked.
    var tabIndex = 
     parseInt($find("<%=tabContainer.ClientId%>").get_activeTabIndex(), 10);
    //set the tabcontainer height to the tab panel height.
    tc.childNodes[1].style.height = 

Don't forget to call doSizeUp when the page loads. Here's something that does that:

var prm = Sys.WebForms.PageRequestManager.getInstance();
function PageLoadedHandler(sender, args) {
    setTimeout('doSizeUp()', 1);

Points of Interest

Please be aware that I only checked this in IE6 and IE7, as that's all that's required when working on our intranet, but I believe it will work in most major browsers.


  • Submitted - 4/25/08.
  • Revised - 4/25/08 - found out another way to do it... probably easier - explained in the introduction.


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


About the Author

Software Developer (Senior) MFA Oil
United States United States
I like puzzles, math, astronomy, books and movies and I read about 3 sci-fi books every month. I also love to laugh. I'm the guy who laughs out loud with headphones on. I know, most of you all hate that guy... but you try to watch this without laughing out loud:

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
lourencosjr7-Apr-11 2:38
memberlourencosjr7-Apr-11 2:38 
AnswerThe Panel suggestion works great! Thanks! Pin
Bill Kuhn10-Mar-10 6:07
memberBill Kuhn10-Mar-10 6:07 
GeneralWorks a treat! Pin
Paul Russo5-Feb-10 3:50
memberPaul Russo5-Feb-10 3:50 
GeneralRe: Works a treat! Pin
PopeDarren21-Dec-11 4:23
memberPopeDarren21-Dec-11 4:23 
GeneralYour updated solution Pin
ek452718-Nov-09 13:26
memberek452718-Nov-09 13:26 
GeneralRe: Your updated solution Pin
PopeDarren21-Dec-11 4:20
memberPopeDarren21-Dec-11 4:20 
GeneralRe: Your updated solution Pin
RockFarmer16-Jan-12 8:43
memberRockFarmer16-Jan-12 8:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190419.4 | Last Updated 25 Apr 2008
Article Copyright 2008 by PopeDarren
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid