Tuesday, February 26, 2008

Making the AjaxToolKit TabContainer tabs vertical

A chat user asked me the other day of how does one put the tabs in the AjaxToolKit TabContainer vertically and I had no idea. I've decided to do it today and write this blog post, maybe he'll come back and he'd get the answer.

So, the request is simple: take a web site with a TabContainer in it and make it show the tabs vertically. I can only assume that the vertical tabs would go on the left and the content in the right. So I took the Internet Developer Toolbar and analysed the html output of a page with four static tabs. I added a <style> tag with CSS classes and started making changes until it worked. Unfortunately, the same setup would not work on Firefox, so I had to repeat the process using Firebug to analyse the page output. In the end this is the result:
.ajax__tab_header {
.ajax__tab_body {
.ajax__tab_outer {
display:block !important;
height:auto !important;

Add this on top of your page or include it in your CSS and the tabs will appear vertically.

Now for a bit of explaining.
  • First of all this does not overwrite the CSS that the TabContainer loads because it is organized under a general ajax__tab_xp class like: .ajax__tab_xp .ajax__tab_header .
  • Then the width of 200px is arbitrary. I used it to keep the vertical tabs at the same width. I tried using min-width first, but it won't display right in Firefox.
  • Another point is about the ajax__tab_body class that I tried to set up first as float left, which would place the body div next to the tabs div, however this breaks if the body tab is wider and the content would appear underneath the tabs div. Thanks to my colleague Romeo I used the margin-left trick. 220px is enough to work in both IE and Firefox. It can be made smaller (closer to 200px)if the default IE body margin would be 0.
  • The !important keyword is placed to overwrite some settings that are already set up in the original TabContainer CSS.
  • Last issue: now the right panel will be truncated if it gets too large. You should control the overflow of that div, although, as far as I am concerned, my job is done

As a kind of disclaimer, I am not a CSS expert. If you know of a better way of doing this, please let me know.


Anonymous said...


You seem to have a good grasp of this subject, noting blog from last year - I have an issue with a TabContainer and dynamically adding Tabs.

The DB returns a list of Types - with maybe six values - and the tabs are supposed to be instantiated to contain small lists of items of that Type in a separate DB Select...

The problem is I can't tie the Page.LoadTemplate template to a particular DB select statement, it is dependent on the Type.

Nor do I want to ideally - all I really want to do is assign a populated GridView to each Tab as a prebuilt control - ie.
thisTab.Controls.Add( gridview );
thisTabContainer.Add( thisTab );

Maybe I have missed something. Can you help? Many thanks.

Siderite said...

I could help if you explain it better. Can't you use the chat so we can talk in real time?

From what I understand, you want to create tabs in a tab container dynamically and add stuff to them.

Doesn't this post help: http://siderite.blogspot.com/2007/07/fixing-tabcontainer-to-work-with.html ?

Or is the problem that you can't add stuff to them because they are templated controls? I did an application where I was dynamically adding TabPanel objects and I didn't really need an ITemplate. Just:
TabPanel tb=new TabPanel();

Anonymous said...

public class TC : TemplateControl, ITemplate
private GridView _g;
public GridView Grid
get { return _g; }
set { _g = value;
this.Controls.Add( _g );

#region ITemplate Members

public void InstantiateIn( Control container )
container.Controls.Add( this );


Is the only way I have found to get over the problem!

If you add a control to TabPanel using the controls collection, something in AJAX kicks up about a "null handler" property.

I admit the AJAX documentation is not great!

wrathyimp said...

Hi siderite,

I applied your style to make the tabs vertical. the tab header are now vertically align, but the tab body is coming below the tab headers.

Could please suggest or guide to fix this little issue. thanks.

Siderite said...

Well, try to use Internet Explorer Developer Toolbar or FireBug to see what is wrong and tweak it until it works. Maybe the width of the screen is too small? What browser are you using?

Search for me in the chat window.

Madhanlal said...

Your code for vertical tab helps me very much. Thank you.

Anonymous said...

Does anyone have a link to a working example? Thanks

vhrao said...

How can I add a drop down menu to a horizontal tab. I defined a simple ul based listing in HeaderTemplate and it does not work.

Anonymous said...

Thank you. It helped a lot.

Anonymous said...

Brilliant thanks. Just what i was looking for.

Anonymous said...

Wow! Thanks a lot. I've been searching high and low on how to make the tabbed panels veritcally..and your solution is so simple and works perfect!!

TyB said...

THANK YOU! I just added the new TabContainer control from the .Net 4 AjaxToolKit which introduces the vertical tab.

Problem is that there is a major bug if you use vertical tabs. If you change any default property of the tab or controls in the tabs it throws a JScript error.

If your interested in more detail with my problem see http://forums.asp.net/p/1760620/4797507.aspx/1?p=True&t=634629383826677143.

Thanks TyB

Siderite said...

Glad I could help. When I wrote this post I don't think they even had vertical tabs as an option.

Nelviticus said...

Thanks from me too. I had the same problem as TyB - TabContainer supports vertical tabs in the current version but they are broken. The script tries to set a 'spanner height' to a negative value, which works in Firefox/Chrome but fails in IE.

Unknown said...

Yep - The verticle tab capability in the AJAX tabcontainer has at least a couple of serious bugs which haven't been addressed as of the June 2012 release :(

They work fine in Chrome and IE9, but break badly in IE8.

Anonymous said...

thanks its good article

Anonymous said...

thnx dude ur code helps me....

Gauri said...

Great explanation! This solution worked Just About Right!