Blog - Microsoft .NET, ASP.NET, AJAX and more

AJAX Control Toolkit - Tab Control - Themes

by Damien White 9/26/2007 8:56:50 PM

There seems to be a lot of issues on the ASP.NET Forums with "Theming" the AJAX Control Toolkit's Tab Control. There are lots of requests for samples (one example), but there are limited resources out there. Looking at the Tabs sample page, you will find information on Theming, but it's pretty basic. You will find the various styles that affect the tabs on the bottom of the sample page. Even with this, it leaves something out and people have problems.   I believe the thing that throws people off is how the sample states "If your CssClass does not provide values for any of those then it falls back to the default value."; the default value for the tabs are extremely basic.  The style you most frequently see is the XP tab style (more on this later).

I feel you should begin by looking at the structure of the tab HTML to truly understand how it works. If you are curious about the other HTML structure, check out Firebug. The power of Firebug is truly amazing; this is a sample screenshot but doesn't even come close to paying Firebug justice:

[If anyone from the Microsoft IE team is listening; PLEASE give us this power in IE7 or IE8, the Internet Explorer Developer Toolbar is ok, but it just feels crippled next to Firebug and "Firebug Lite" doesn't fill any of the real gap.]

Let's take a closer look at the tab structure:

01 <span id="..." class="ajax__tab_active">
02   <span class="ajax__tab_outer">
03     <span class="ajax__tab_inner">
04       <span id="..." class="ajax__tab_tab">Tab 1</span>
05    </span>
06  </span>
07 </span>

 

As you can see, a tab is constructed of nested <span> tags. The class ajax__tab_outer defines the right side of the tab, the class ajax__tab_inner defines the left side of the tab, and finally ajax__tab_tab defines the middle of the tab as this image shows:

 

 

Now that we understand the tab structure, let's work on some styles. In this example, we'll clone the tab styles of Internet Explorer 7 (IE7) under Windows XP. The easiest way to create new styles is to copy that of the ajax__tab_xp which is the default style that you typically see. Browsing the source of the Tab control (which you can download from Codeplex), navigate to the AjaxControlToolkit\Tabs folder and open up Tabs.css. You will find a section called xp theme; this is what we are copying. Looking at the CSS you'll see that the effects for the tab are created using images and for the IE7 style, we will do the same. So in copying the XP style, we create the following images:

  • tab-line.gif – Used to underline the header
  • tab-right – The right side of the inactive tab
  • tab-left – The left side (outer) of the inactive tab
  • tab – The inner portion (tab) of the inactive tab
  • tab-right-hover – The right side of the hover tab
  • tab-left-hover – The left side (outer) of the hover tab
  • tab-hover – The inner portion (tab) of the hover tab
  • tab-right-active – The right side of the active tab
  • tab-left-active – The left side (outer) of the active tab
  • tab-active – The inner portion (tab) of the active tab

 

…and finally create the styles (I have separated the background declarations from the other styles just for simplicity of listing and discussions)

First the backgrounds; this is a carbon copy of the ajax__tab_xp with just our new images replacing the embedded ones.

/* IE theme – Backgrounds */

.visoft__tab_xpie7 .ajax__tab_header {
     
background:url(tab-line.gif) repeat-x bottom;
}

.visoft__tab_xpie7 .ajax__tab_outer    {
     
background:url(tab-right.gif) no-repeat right;
}

.visoft__tab_xpie7 .ajax__tab_inner    {
    
background:url(tab-left.gif) no-repeat;
}

.visoft__tab_xpie7 .ajax__tab_tab {
    
background:url(tab.gif) repeat-x;
}

.visoft__tab_xpie7 .ajax__tab_hover .ajax__tab_outer {
    
background:url(tab-hover-right.gif) no-repeat right;
}

.visoft__tab_xpie7 .ajax__tab_hover .ajax__tab_inner {
    
background:url(tab-hover-left.gif) no-repeat;
}

.visoft__tab_xpie7 .ajax__tab_hover .ajax__tab_tab {
    
background:url(tab-hover.gif) repeat-x;
}

.visoft__tab_xpie7 .ajax__tab_active .ajax__tab_outer {
    
background:url(tab-active-right.gif) no-repeat right;
}

.visoft__tab_xpie7 .ajax__tab_active .ajax__tab_inner {
    
background:url(tab-active-left.gif) no-repeat;
}

.visoft__tab_xpie7 .ajax__tab_active .ajax__tab_tab {
     background:url(tab-active.gif) repeat-x;
}

 

Finally, the rest of the styles which we'll change a bit from the ajax__tab_xp styles:

.visoft__tab_xpie7 .ajax__tab_header {
    
font-family:verdana,tahoma,helvetica;
    
font-size:11px;
}

.visoft__tab_xpie7 .ajax__tab_outer {
    
height:29px;
}

.visoft__tab_xpie7 .ajax__tab_inner    {
     padding-left:3px;
}

.visoft__tab_xpie7 .ajax__tab_tab {
    
padding:8px 40px;
     margin:0;
}

.visoft__tab_xpie7 .ajax__tab_body
    
font-family:verdana,tahoma,helvetica
    
font-size:10pt;
    
border:1px solid #999999;
    
border-top:0;
    
padding:8px;
    
background-color:#ffffff;
}

Most of the styles are arbitrary (and most are copies from the ajax__tab_xp styles), but the two import styles that effect the tab are the height and padding, underlined in the sample above. The height matches that of the tab images while the padding increases the width and centers the text vertically and horizontally. You could set different left and right paddings to change the text alignment, but in this example we have it centered.

The last thing we need to do is to add the custom CssClass to the Tab Container:

<ajaxcontroltoolkit:tabcontainer id="tabContainer" runat="server" height="300" cssclass="visoft__tab_xpie7">

Finally, everything in place; we get the following tab style:

The three styles are represented in the image: tab, active, and hover. Not a bad reproduction from the original. Obviously, we don't have an image in the header in this example, but this can always be added using the <headertemplate> of the Tab Panel. You can also go a bit farther with the replication and add the thin bar that is below the tabs.

 

 

If you'd like, you can download the files for this sample: Full Solution | CSS and Images Only

Shout it kick it on DotNetKicks.com Bookmark and Share

Comments

10/4/2007 6:30:25 PM #

james

sweet, just what i was looking for Laughing thanks very much

james

10/8/2007 7:33:07 PM #

Brad

What about styling each tab panel differently? I am trying to implement a simple style where I have three tabs and each one is a different color (red, green, blue)

Styling the container works but it gives me the same style for each tab. I would like to be able to override the styles for the individual tab panel seperatley.

ideas?

Brad

10/24/2007 8:07:30 AM #

Gustavo Sarti

Thank you very much!!!
You solved and saved my life with this post!!!
Its a very good site!

Bye

Gustavo Sarti

10/24/2007 8:18:01 AM #

Damien White

Gustavo,
Glad this helped you!  Thanks for the comment.

-Damien

Damien White

10/25/2007 9:44:03 AM #

Sree

Thanks a Trillion sir. Exactly waht i was looking for.

Sree

10/25/2007 1:07:47 PM #

kw7566

this works great! - Next question - any way to change the tab location? I need the tabs on the bottom and on the left (vertical). I have seen 3rd party controls accomplish this feat but was hoping it was feasible with toolkit - wishful thinking?

kw7566

10/25/2007 1:24:26 PM #

Damien White

kw7566 -
It's not impossible, but it will involve some work.  You will need to modify the source for the Tabs control, the good news is all you need to modify is the rendering and not the logic.
-Damien

Damien White

11/6/2007 7:15:34 AM #

Oscar

Very good post and nice result, but it's giving me problems in IE 6.0:

www.hagasesuweb.com/imagenes/problem_explorer.gif

Any suggestion is welcomed

Thx

Oscar

11/6/2007 7:42:39 AM #

Damien White

Oscar,
It looks to me like IE6 is being pushed into "Quirks Mode" (see http://en.wikipedia.org/wiki/Quirks_mode" rel="nofollow">http://en.wikipedia.org/wiki/Quirks_mode">http://en.wikipedia.org/wiki/Quirks_mode" rel="nofollow">http://en.wikipedia.org/wiki/Quirks_mode).  The Toolkit assumes the IE is in standards rendering mode...  I believe the faulty box model is IE6 Quirks Mode is to blame for you issue.  Check the Wiki and make sure you use one of the standard-rendering DOCTYPE declarations.  Hope this helps!
-Damien

Damien White

11/6/2007 10:34:49 AM #

Oscar

Thx so much for ur quick answer. I'm gonna check it just now and I'll tell u!

Bye

Oscar

11/6/2007 11:57:12 AM #

Oscar

Ok, let's see if i've understood:

my old configuration was:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" rel="nofollow">www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

and checking the wiki article, for having A (S is not possible) in IE6 i've to put:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" rel="nofollow">www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

That is the same save to the line <?xml...>

But this doesn´t fix the problem. Am i doing right?

thx

Oscar

11/6/2007 12:25:03 PM #

Damien White

Oscar-
Your old DOCTYPE should be correct:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">.

Make sure you don't have anything before the doctype, such as the XML declaration or a comment.  IE6 gets pushed into Quirks Mode when there is something before the DOCTYPE.  Look at the source of your rendered page to make sure the DOCTYPE is the first line.

If it isn't quirks mode causing your issue, it could be possible that you have another style on your site that may be effecting it.  For example if you have something like SPAN { padding: 10px; }, this will apply a 10px padding to all SPANS, causing you issues with your tabs.

I'd recommend using the IE Developer Toolbar to attempt to troubleshoot your issue.  Sometimes these things are pain to track down...

Does the "standard" XP style work successfully for you?  If this does, then you may have to adjust the padding or something when you create your new theme.  

Hope you find your issue!
-Damien

Damien White

11/6/2007 12:56:06 PM #

Oscar

It works! u were totally in the first thing u thought: I had a SPAN style definition. The problem: line-height:30px.

Thx so much, u've helped a lot and I've learnt also.

Oscar

11/21/2007 12:14:44 PM #

Damon

Brilliant explanation. Clear and precise.

Saved me alot of time

Damon

11/21/2007 8:18:18 PM #

Dondi

I still don't quite get it. Does that mean I replace the css in the ajax project recompile it and then reinstall ajax on my pc for the changes to take affect?

Dondi

11/21/2007 8:29:30 PM #

Damien White

Dondi,
No, you don't need to recompile at all.  Just add your stylesheet to your page and add your custom CSS class name.  www.visoftinc.com/.../AJAXTabThemingSample.zip">Download the demo and it should be clearer.

Damien White

12/6/2007 6:21:25 PM #

Jay K

Do you know a way to change the style for just one of the tab panels?  For example, if I have a container w/ 3 panels and if the user meet a cetain criteria, I would like to "flag" the third tab (highlight in red or something like that) so the user knows to go there after looking over the info on the default panel.

Thanks

Jay K

12/6/2007 8:48:09 PM #

Damien White

Jay -
Your best bet is to use an image or something within the HeaderTemplate for the tab to indicate there is something "special" about it.

-Damien

Damien White

12/11/2007 2:43:34 PM #

jana

Hi,
You explanation si very good and useful. I am trying to use this, Everything is working fine but background image is not coming. I am using IE7.
Images are copied to respective dir.

Could you please suggest me what else could be wrong.?

jana

1/3/2008 1:19:35 AM #

Mahbubul Alam

my need  AJAX Control Toolkit - Tab Control - Themes

Mahbubul Alam

1/3/2008 8:19:05 AM #

Damien White

Mahbubul -
Are you looking for the source code?  It's available at the end of the article: Look for the line "If you'd like, you can download the files for this sample: www.visoftinc.com/.../AJAXTabThemingSample.zip">Full Solution | www.visoftinc.com/.../visoft__tab_xpie7CSS.zip">CSS and Images Only"

-Damien

Damien White

1/9/2008 7:24:40 AM #

Hans

Hi,
Is there a way to put the tabs on the left side and not on top?

greetings,

hans

Hans

1/10/2008 3:15:38 PM #

Matt

Is there anyway to make the tabs all the same length no matter what the header text length is?

Matt

1/11/2008 11:42:08 AM #

Damien White

Matt -
For a fixed width, just set a width on the ajax__tab_tab.  For example:
width:100px;
Note that this may mess up your layout a bit though based on the overall width of your tabs, so you may have to play around with it.  

-Damien

Damien White

1/11/2008 11:46:30 AM #

Damien White

Hans -
Tabs on the Left  are a bit tricky, but not impossible.  You will need to modify the source for the Tabs control, the good news is all you need to modify is the rendering and not the logic.

There are also other products out there that do this, for example: http://dhtmlx.com/docs/products/dhtmlxTabbar/

-Damien

Damien White

1/22/2008 7:01:10 AM #

Poornima

hai,
In my tab control the header text is displaying half of the text and remaining is white space.?

thanks

Poornima

1/29/2008 2:15:16 PM #

Seattle Willy

Very cool. I am working with the YUI theme and found your examples very clear and concise. Good job.

Seattle Willy

2/5/2008 2:04:12 PM #

Robert Jackson

I'm trying to change the color based on the tab selected through client side. Probably within the OnClientActiveTabChanged.  Has anyone been able to do this?

Robert Jackson

2/19/2008 9:15:46 AM #

Thiago Loureiro

Congratulations, your code works perfect here!! thank you!!!

Thiago Loureiro

2/20/2008 12:01:16 PM #

Mohammed Adel El-Khodary

Thank you so much for your valued post.

Mohammed Adel El-Khodary

2/22/2008 8:15:15 AM #

AC

Awesome - a great, clear and easy to follow piece of advice - thanks very much!

AC

3/14/2008 3:41:31 PM #

Chris

Great example.  I was able to open/run it without any problems.

However, I copied/pasted the ajaxtoolkit source from default.aspx into a content page like:
<%@ Page Language="C#" MasterPageFile="~/myMaster.master" AutoEventWireup="true" CodeFile="dummy.aspx.cs" Inherits="dummy" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ScorePlaceHolder" Runat="Server">
     <asp:scriptmanager id="ScriptManager1" runat="server"></asp:scriptmanager>  
    <ajaxToolkit:tabcontainer id="tabContainer1" runat="server" height="300" cssclass="visoft__tab_xpie7">
        <ajaxToolkit:tabpanel id="tabPanel1" headertext="Tab 1" runat="server">
            <contenttemplate>Test - Tab 1</contenttemplate>
        </ajaxToolkit:tabpanel>
        <ajaxToolkit:tabpanel id="tabPanel2" headertext="Tab 2" runat="server">
            <contenttemplate>Test - Tab 2</contenttemplate>
        </ajaxToolkit:tabpanel>
        <ajaxToolkit:tabpanel id="tabPanel3" headertext="Tab 3" runat="server">
            <contenttemplate>Test - Tab 3</contenttemplate>
        </ajaxToolkit:tabpanel>
        <ajaxToolkit:tabpanel id="tabPanel4" headertext="Tab 4" runat="server">
            <contenttemplate>Test - Tab 4</contenttemplate>
        </ajaxToolkit:tabpanel>        
    </ajaxToolkit:tabcontainer>
</asp:Content>

The CSS stopped working.  I don't know why(the page will load and function, no styling).  Is there something specific you have to do to make CSS/Content work with AJAX/Tabs?  I included the css file in the master page header.

Chris United States

3/15/2008 12:52:23 AM #

Damien White

Chris -
You need to include the CSS stylesheet for the tab styles either in your MasterPage or you can add a stylesheet for the specific page using the technique found here: snipplr.com/.../.

Hope this helps!
-Damien

Damien White United States

3/15/2008 7:46:07 PM #

prasad

Inspired by this post, I made some more nice looking themes. here you go

digdotnet.blogspot.com/.../...colorful-themes.html

Prasad.

prasad United States

3/15/2008 7:51:04 PM #

Damien White

Prasad -
Thanks for sharing these, I'm sure these will help out many users.

-Damien

Damien White United States

3/17/2008 6:40:55 PM #

Chris


Chris -
You need to include the CSS stylesheet for the tab styles either in your MasterPage or you can add a stylesheet for the specific page using the technique found here: snipplr.com/.../.

Hope this helps!
-Damien

I tried including the css file in both ways mentioned, however, that didn't seem to help.  Below is the code for the master page.

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="myMaster.master.cs" Inherits="myMaster" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/.../xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
   <link type="text/css" rel="stylesheet" href="Stylesheets/visoft__tab_xpie7.css" />  
   <link type="text/css" rel="stylesheet" href="Stylesheets/StyleSheet.css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
        </asp:contentplaceholder>
    </div>
   <br />
   <br />
   <span class="Test">This is another test.</span>
    </form>
</body>
</html>

Below is the final rendering of the head tag only.
<head><title>
  Untitled Page
</title><link type="text/css" rel="stylesheet" href="Stylesheets/visoft__tab_xpie7.css" /><link type="text/css" rel="stylesheet" href="Stylesheets/StyleSheet.css" /><link href="StyleSheets/visoft__tab_xpie7.css" rel="stylesheet" type="text/css" /><link href="/scorecard/WebResource.axd?d=oMNrY_T3KXTsOSsbu9yz1pcY2cFaQlMpY6g0TgmJfxm290LkzUJJakdWKIU5zCGyidjWWvInGD14h12ipbeT-w2&amp;t=633310672420000000" type="text/css" rel="stylesheet" /></head>

(I'll take out one of the two visoft__tab_xpie7 references when this starts to work)

I added a css class called "Test" which turns text green and included it in StyleSheet.css and then cut/pasted it into visoft__tab_xpie7.css, both times it turned the text green as it should.  So the stylesheet is getting loaded.  Is there something I'm forgeting?  Thanks for your help Damien.

Chris United States

3/17/2008 7:04:03 PM #

Damien White

Chris,
It looks correct, however is the path correct?  For example, you are using a relative link, but based on the position of the page your path maybe off.  One thing you can try is set your link to be runat="server" and use a path of ~/StyleSheets/visoft__tab_xpie7.css assuming the StyleSheets folder is off of the root.  You can also use FireBug (http://getfirebug.com) in FireFox and it will show you the loaded CSS files.

I'm not sure if you use themes, but it maybe a good idea since theme stylesheets are included automatically and the path will be correct.  You can get more information on MSDN: msdn2.microsoft.com/en-us/library/ykzx33wh.aspx.

-Damien

Damien White United States

3/22/2008 7:50:41 AM #

mark

Hi Damien

I've been looking every where for this answer so i'm hoping you can help

I'm looking to style individual tabs, i want to change the colour of a few of them (grey them out)
I've changed the CSSCLASS on the individual tabs but it doesn't seem to get applied to the tabs

can you tell me if this is possible or how i can tackle it?
thanks

mark United Kingdom

3/22/2008 9:34:53 AM #

Damien White

Mark,
I don't think changing the individual tab style (e.g. the background) is possible without modifications to the Tab Control's source code.  You can do some customization using the HeaderTemplate, but this doesn't change the full rendering of the tab, it just adds your header template code into the inner most SPAN of the tab itself.  Also, if you are trying to disable a tab, you would need more than just CSS to accomplish this.  There is a post on the ASP.NET forums that may help you out in doing this, although I haven't taken the time to try it out for myself:  http://forums.asp.net/t/1074319.aspx.

-Damien

Damien White United States

3/25/2008 8:36:15 AM #

Kartik

Is there any way to set all tabs vertically ?

Kartik India

3/31/2008 4:16:37 PM #

SeanD

Damien,
EXCELLENT Post.

My only addition is that I added ["border-top: #B9D3FB 5px solid;" to the .visoft__tab_xpie7 .ajax__tab_body {} style.  That gives a solid blue line accross the whole bottom of the TabContainer Control (by putting it on the TOP of the content block).

Sean D.

SeanD United States

4/2/2008 4:07:58 PM #

Reymes M-R

Hi there Damien,
Thanks a lot for sharing that info about Tab-themes. I dealing with some other problem. I am trying to used those themes, but at the same time I need to put another Tab Control inside each Panel of a general Tab-Control. The problem is that the inner-Tab-Controls do not display the specified theme. Theme is showed only one for the outer Tab-Control.
Any idea of what is going on?
Thanks in advance

Reymes M-R Canada

4/2/2008 4:45:04 PM #

Damien White

Reymes-
If you don't set a CSSClass for the inner tab control, do you get the standard "XP" styles?  I haven't tested nested tabs before, so I'm interested as to what happens.

Damien White United States

4/3/2008 5:47:48 AM #

Joop Stringer

Hi there,

I'm trying to use Theming (App_themes folder ) in the CSS, but then the gif's are not shown. It only works when I put the images in images folder under the root.


.visoft__tab_xpie7 .ajax__tab_header  { background:url(images/tab/tab-line.gif) repeat-x bottom; }
.visoft__tab_xpie7 .ajax__tab_outer  { background:url(images/tab/tab-right.gif) no-repeat right; }
.visoft__tab_xpie7 .ajax__tab_inner  { background:url(images/tab/tab-left.gif) no-repeat; }
.visoft__tab_xpie7 .ajax__tab_tab  { background:url(images/tab/tab.gif) repeat-x; }
.visoft__tab_xpie7 .ajax__tab_hover .ajax__tab_outer  { background:url(App_Themes/galcho/images/tab/tab-hover-right.gif) no-repeat right; }
.visoft__tab_xpie7 .ajax__tab_hover .ajax__tab_inner  { background:url(App_Themes/galcho/images/tab/tab-hover-left.gif) no-repeat; }
.visoft__tab_xpie7 .ajax__tab_hover .ajax__tab_tab    { background:url(App_Themes/galcho/images/tab/tab-hover.gif) repeat-x; }
.visoft__tab_xpie7 .ajax__tab_active .ajax__tab_outer  { background:url(images/tab/tab-active-right.gif) no-repeat right; }
.visoft__tab_xpie7 .ajax__tab_active .ajax__tab_inner  { background:url(images/tab/tab-active-left.gif) no-repeat; }
.visoft__tab_xpie7 .ajax__tab_active .ajax__tab_tab    { background:url(images/tab/tab-active.gif) repeat-x; }

Here the HOVER images are not show.
Any suggestion ?

Joop Stringer Netherlands

4/3/2008 6:28:28 AM #

Damien White

Joop -
To use themes, you can put your CSS in your "App_Themes/galcho" folder.  You can call it tab.css.  Also, you can have your images folder in your theme (e.g. "App_Themes/galcho/images") as well.  Add all your images for your theme in there.  For the CSS, you don't have to specify a <link> in the master page for it since the theme will automatically add the tab.css to your page.  Once you have this structure, you can simply use a path relative to the CSS file (so just "images/tab/tab-hover.gif" instead of the full "App_Themes/galcho/images/tab/tab-hover.gif" path).  If you need more help, check out quickstarts.asp.net/.../default.aspx.

-Damien

Damien White United States

4/4/2008 4:06:07 PM #

Joop Stringer

Hi Damien,

Don't know what went wrong.
It works fine now.

My CSS is in the App_themes folder and the styles for the tabs are like this:
.visoft__tab_xpie7 .ajax__tab_inner { background:url(images/tab/tab-left.gif) no-repeat; }

tab-pictures are in App_Themes\galcho\images\tab

Thanks,
Joop

Joop Stringer Netherlands

5/9/2008 9:01:46 PM #

Jason Monroe

@Mark & Damien

RE: styling of individual tabs

I recently had this requirement come up with a client... Normally I would have used the Telerik Tab control to do this, but they were unwilling to budge on that regard.  So I looked through the TapContainer control in the toolkit and was able to successfully apply unique styles.  This blog post outlines my experiences in dealing with, and work around the TabPanel limitations imposed by the control toolkit.

clanmonroe.com/.../...bs---ajaxcontroltoolkit.aspx

Jason Monroe United States

5/28/2008 1:58:41 PM #

locoHost

Fantastic article!! Works perfectly. You saved me so much time!

locoHost United States

6/5/2008 6:57:57 AM #

Ronnie Mukherjee

Very helpful, thanks.

Ronnie Mukherjee United Kingdom

6/18/2008 10:32:49 AM #

Holly

Thank you very much. Just what I was looking for Smile

Holly United States

7/9/2008 11:29:53 PM #

VV

I am using tabcontainer with 3 tab panels with XHTML 1.0 transitional doctype. It works well within IE7, but in firefox it does not display the border for the first panel correctly. The border height is less than the content height. I am also using the CSS but not using styles for the tabs. What may be the problem?
Thanks.

VV United States

7/10/2008 9:01:29 AM #

Damien White

VV -
I'm not sure what could be wrong based on the information that you provided.  I would use Firebug (http://getfirebug.com/) to debug your styles in Firefox.  Your DOCTYPE shouldn't be a problem, it should be rendering in standards mode in both IE and Firefox.  

-Damien

Damien White United States

7/14/2008 8:36:07 AM #

rualmar

Hi Damien and thanks for that wonderful work.

I'm trying your theme and I'm having some weird problems.

- In first place, when I open it with firefox, the tabs doesn't reach the tabcontrol body, so there is a white line between them (between the tabs and the body). The weird thing is that it happens randomly depending on the computer where I'm viewing it (having the same screen setup, browser settings, etc...)

- Second: some of the tabs have an imagebutton on it, but when I put them, the ones that have the button stay higher than the ones which doesn't have, being that last ones on the right position.

Well, there are some more problems but all derived from these.

I've tried changing paddings, margins, using tables and divs to make the header templates, etc... but I haven't reached a solution. I can only see it well on IE7, but on IE6 and Firefox I keep having those problems.

Any advice? Thanks in advance.

rualmar Spain

7/14/2008 9:31:39 AM #

Damien White

Rualmar -
Since you are having problems on different computers, it sounds like your problem may have to do with something like font-size.  If one computer has the font set to Large and another Medium, it could cause some problems since the tabs are fixed heights.  Do you have font-size set to a fixed size (e.g. font-size: 11px;)?  In terms of your ImageButton, my guess is that your problem has to do with height of the tab vs the default height.  You need to set all the tabs to be the same height has the ImageButton tabs.  Also, you may need to modify your tab background to compensate for the new height.

Other things to try/check...  
1. Make sure you are using a Standards Mode DOCTYPE: http://en.wikipedia.org/wiki/Quirks_mode
2. Use Firebug (http://getfirebug.com/) to test your styles out in Firefox.  There is a chance that you have some conflicting style causing you issues.

Hope this helps
-Damien

Damien White United States

7/15/2008 3:18:49 AM #

rualmar

Hi Damien, and thank you for the answer.

I've been trying out all you said, but I haven't found any solution yet. About the font size, I have the same settings on all the computers I've tried it and, for the CSS, it has set the 11px font-size that you set by default.

About the images, their height is 21 px, so it's less than the height of the background image (29 px). I've used Firebug (thank you for pointing out such powerful tool) to check the style that applies to them and here they are:

.ajax__tab_default .ajax__tab_tab
{
cursor:pointer;
text-align:center;
}

.ajax__tab_default .ajax__tab_header
{
white-space:nowrap;
}

.ajax__tab_header
{
font-family:verdana,tahoma,helvetica;
font-size:11px;
}

element.style {
border-collapse:collapse;
}


It seems they are the default styles that you're aplying with your theme.

I've also checked the styles aplying to all the tabs and the elements inside them and they're exactly the same.

What I've found is that, inside the tabContainer_header div, the span elements which represent the tabs without images have a size of Nx12 while the size of the ones with the image on it is Nx3 (where N is the width depending on the text inside it). Check it out here: img378.imageshack.us/img378/1880/tabsizesxp3.png

I've tried modidying styles, but I can't fix that. Any idea about it? Thanks again.

rualmar Spain

7/15/2008 3:23:39 AM #

rualmar

Sorry for the double comment, but the image was wrong, the titles were changed. This is the rigt one:

img387.imageshack.us/img387/9213/tabsizesso3.png

And here's the tabs state rigt now:

img387.imageshack.us/img387/8813/tabszy6.png

(I deleted the "padding: 8px 40px;" property trying to fix the problem, with it active, the text goes on the middle of its tab  and their width grow)

rualmar Spain

7/15/2008 6:34:22 AM #

rualmar

Hi Damien, and thank you for the fast response.

I posted a comment a while ago, but it got deleted....maybe for posting an imageshack url? I was trying to show you the state of my tabs, and something I discovered with firebug (by the way, thanks for pointing out that tool).

First of all, I've checked all you said and I think it's all right. I've seen you mention things about the DOCTYPE on other post, but everything seems to be OK. And about the styles, actually there are only the ones that you have by default in your theme.

The thing I've discovered is that the height of the span that contains the tab changes between the tabs with an image on it (3px) and the ones without it (12px). I can't change it manually, even with firebug or other real-time CSS editors.

Could this be the source of the error? Because that only happens when I put an image on the tab. If I remove the image from all the tabs, I can fix the display by adjusting paddings and margins.

Any idea about this? Thanks in advance.

P.S.: If there's any way to post images I can show you the tabs and the firebug reports.

rualmar Spain

7/15/2008 9:01:57 AM #

Damien White

Rualmar -
It looks like the padding (perhaps margin) and height is causing your problems.  The styles I have in this example are to place the text in the center of the tab.  To make everything line up, you should have the same tab height for the text ones as well as the image tabs.  I would focus on working with padding and the height.  Remember that the background images are what create the tab structure, so you will most likely need to modify the height of these as well.

Hope this helps.
-Damien

Damien White United States

7/24/2008 3:51:24 AM #

rualmar

Hi Damien.

I just can't fix the tabs structure. One solution I've came with is having all the tabs with images, but using a transparent png in the ones without button. The problem is that transparency doesn't work nice on IE6.

Thanks a lot for your help.

rualmar Spain

7/24/2008 8:50:34 AM #

Damien White

Rualmar -
That's one way to do it.  Why not use a transparent GIF instead of a PNG?  IE6 will be fine with a GIF.
-Damien

Damien White United States

7/27/2008 2:46:19 AM #

Hung

What a useful article. It's exactly what I'm searching for.
Thanks a lot.

Hung Vietnam

8/5/2008 8:59:55 PM #

Gary

Hi Damien,

I am working with nested AJAX Tab controls. I am using background images for the outer tab control's tabs. I need to increase the height of parent control's tabs to match the background image dimensions but this is creating the problem for inner (child) AJAX tab control's tabs dimensions. As you can see below in the style sheet below, I have defined the width and height in the inner tab control as well but it still picks up the width and height from the parent control's style sheet. Any help on this would be greatly appreciated.

Thanks,
Gary


<ajaxToolkit:TabContainer ID="tcControlPanel" runat="server" ActiveTabIndex="0" Width="930px" CssClass="TabOuter" OnClientActiveTabChanged="templateActiveTabChanged">
  <ajaxToolkit:TabPanel ID="tpnlLayoutDesigner" runat="server" Width="930px">
    <HeaderTemplate>
         <asp:Label ID="lblTS" runat="server" Text="&nbsp; Template &nbsp; " CssClass="tabText"></asp:Label>
    </HeaderTemplate>
    <ContentTemplate>
      <ajaxToolkit:TabContainer ID="tcLayoutDesigner" runat="server" ActiveTabIndex="0" Width="900px" CssClass="TabInner" Height="70px">
        <ajaxToolkit:TabPanel ID="tpnlFont" runat="server" Width="900px">
          <HeaderTemplate>
          </HeaderTemplate>
          <ContentTemplate>
          </ContentTemplate>
        </ajaxToolkit:TabPanel>
    </ContentTemplate>
  </ajaxToolkit:TabPanel>
</ajaxToolkit:TabPanel>



.TabOuter
{
  display: block;
}

.TabOuter .ajax__tab_header
{
  font-family: verdana,tahoma,helvetica;
  font-size: 11px;
  border-bottom-color: #98B5C3;
  border-bottom-width: 1px;
  border-bottom-style: solid;
  height: 21px;
}
.TabOuter .ajax__tab_outer
{
  height: 21px;
}
.TabOuter .ajax__tab_inner
{

}
.TabOuter .ajax__tab_tab
{
  background-image: url(images/non_active_tab.gif);
  background-repeat: no-repeat;
  background-color: #E0EFF6;
  
  border-top-color: White;
  border-top-width: 1px;
  border-top-style: solid;
  
  color: #0F5B82;
  padding-top: 2px;
  padding-bottom: 4px;
  padding-left :4px;
  height: 26px;
  width: 150px;
}


.TabOuter .ajax__tab_hover .ajax__tab_outer
{
}
.TabOuter .ajax__tab_hover .ajax__tab_inner
{
}
.TabOuter .ajax__tab_hover .ajax__tab_tab
{
}

.TabsOuter .ajax__tab_hover .ajax__tab_active .ajax__tab_tab
{
}

.TabOuter .ajax__tab_active .ajax__tab_outer
{
  height: 21px;
}

.TabOuter .ajax__tab_active .ajax__tab_tab
{
  background-image: url(images/active_tab.gif);
  background-repeat: no-repeat;
  background-color: White;
  
  border-top-color: White;
  border-top-width: 1px;
  border-top-style: solid;
  
  color: #0F5B82;
  
  font-weight: bold;
  padding-top: 0px;
  
  height: 26px;
  width: 150px;   
}
.TabOuter .ajax__tab_body
{
  font-family: verdana,tahoma,helvetica;
  font-size: 10pt;
  border: 1px solid #98B5C3;
  border-top: 0;
  padding-left: 2px;
  padding-right: 2px;
  padding-top: 0px;
  background-color: #ffffff;
}


/*INNER (CHILD) TAB CONTROL STYLE*/

.TabInner
{
  display: block;
  top: 0px;
}

.TabInner .ajax__tab_header
{
  font-family: verdana,tahoma,helvetica;
  font-size: 11px;
  border-bottom-color: #98B5C3;
  border-bottom-width: 1px;
  border-bottom-style: solid;
  height: 21px;
}
.TabInner .ajax__tab_outer
{
  height: 21px;
}
.TabInner .ajax__tab_inner
{
}
.TabInner .ajax__tab_tab
{
  background-image: url('');
  background-color: #E0EFF6;
  border-left-color: #98B5C3;
  border-left-width: 1px;
  border-left-style: solid;
  border-right-color: #98B5C3;
  border-right-width: 1px;
  border-right-style: solid;
  border-top-color: #98B5C3;
  border-top-width: 1px;
  border-top-style: solid;
  color: #0F5B82;
  padding-top: 2px;
  padding-bottom: 4px;
  height: 21px;  
}


.TabInner .ajax__tab_hover .ajax__tab_outer
{
}
.TabInner .ajax__tab_hover .ajax__tab_inner
{
}
.TabInner .ajax__tab_hover .ajax__tab_tab
{
}
.TabInner .ajax__tab_active .ajax__tab_outer
{
  height: 22px;
}
.TabInner .ajax__tab_active .ajax__tab_inner
{
}
.TabInner .ajax__tab_active .ajax__tab_tab
{
  background-image: url('');
  background-color: White;
  border-left-color: #98B5C3;
  border-left-width: 1px;
  border-left-style: solid;
  border-right-color: #98B5C3;
  border-right-width: 1px;
  border-right-style: solid;
  border-top-color: #98B5C3;
  border-top-width: 1px;
  border-top-style: solid;
  color: #0F5B82;
  font-weight: bold;
  padding-top: 4px;
  padding-bottom: 4px;
  height: 21px;
}
.TabInner .ajax__tab_body
{
  font-family: verdana,tahoma,helvetica;
  font-size: 10pt;
  border: 1px solid #98B5C3;
  border-top: 0;
  padding: 8px;
  background-color: #ffffff;
}

Gary United States

8/5/2008 9:11:00 PM #

Damien White

Gary -
My initial guess (I haven't tried out your code yet) is that a parent style is causing your issue.  Make sure that you override the parent properties in the child.  For example, if you have a height on the parent, but don't have it set on the child, the child will use the parents since the inner css class names are the same.  Try using Firebug or the IE Developer Toolbar to trace the problematic style.

Let me know if this helps.
-Damien

Damien White United States

8/5/2008 10:18:47 PM #

Gary

Damien,

Thank you for your quick response. I figured out the issue.

It had to do with exact pixel size on the child control. I had defined the properties on the child as well but I had to find the exact pixels size that worked for the child control.

Anyways, thank you for good explanation on the AJAX Tab control CSS classes. Great job. God bless you.

-Gary

Gary United States

8/14/2008 2:26:01 PM #

Jane

I have been working through the example with my own images.  Everything is working good except that I don't understand how to make the line under the active tab not appear.  When I have my tab_line.gif in the ajax__tab_header it shows on the active tab and if I just use the top border of the ajax__tab_body it shows on the active tab.  

Could you explain how you got it to not show the line under the tab on the active tab?

Jane United States

8/14/2008 4:03:16 PM #

Damien White

The line that fills the top is formed by a background image (in this example, .visoft__tab_xpie7 .ajax__tab_header.  The inactive tab background has it's own bottom line to match that of the header, but the active tab simply is just a solid color on the bottom.  This hides the header background, and makes it appear to be cleared since it overlays the header background.

I hope this helps.
-Damien

Damien White United States

8/24/2008 2:30:10 PM #

abhishek

hi.
thanks for your solution but can you tell me how to remove the border line of the tab control?? i mean the side border and bottom border line??? i just wanted to tabs and unders the tab jus one horizontal line....

Is it possible to do????

abhishek India

8/24/2008 2:35:41 PM #

abhishek

But one thing i want to tell that when i am keeping those images in the image folder then those images doesn't appear and when i keep thme outside then it works great...
Can you tell me what will be the URL format to write in the CSS file???

thanks

abhishek India

9/8/2008 10:50:44 AM #

trackback

Trackback from help.net

AJAX Control Toolkit - Tab Control - Themes

help.net

9/24/2008 11:44:43 AM #

Sameh Nabil

Thank you guys; you really saved our day

Sameh Nabil Egypt

9/25/2008 10:10:42 AM #

pingback

Pingback from pavanpabothu.wordpress.com

ASP.NET Ajax TabContainer – Tips and Tricks  « Pavan’s Weblog

pavanpabothu.wordpress.com

10/1/2008 2:34:51 PM #

Babak Bastan

Thank you .. your code has solved my problem 80%.. great!

I tried to align tabs right to left,How can i do that?Is it possible?

Babak Bastan Iran

10/1/2008 2:59:50 PM #

Damien White

Babak -
I haven't tested this, but something like this might work:
.visoft__tab_xpie7 .ajax__tab_header span { float: right; }.  That will reverse the tabs and float them off to the right, so Tab 1 | Tab 2 | Tab 3 would turn into Tab 3 | Tab 2 | Tab 1.
-Damien

Damien White United States

10/1/2008 4:38:54 PM #

Babak Bastan

Thanks Damien
But i mean that Tab 1 | Tab 2 | Tab 3 placed in the right of the page instead of left.
I think its impossible Frown

Babak Bastan Iran

10/1/2008 5:51:35 PM #

Damien White

You could do that with float right, but you would need another container, so if it was like:
header div (existing) >>  tab holder (which you would float: right) >> header tab (existing).  You could modify the source to do this if you wanted.

Don't know if there is another way to do it since I don't have much experience designing right to left interfaces.

-Damien

Damien White United States

10/16/2008 7:20:23 AM #

Sarkie

Hi, have you tried the DebugBar http://www.debugbar.com/, I find it better than Firebug sometimes!

Sarkie United Kingdom

10/21/2008 2:23:48 PM #

baski

Hi

In my tab cotainer the border on the right hand side is not coming properly, i am using.css file as per your steps.Please advise me as soon as possible.

baski

baski United States

11/25/2008 7:29:08 PM #

DaveKan

I have an ASP bulleted list in each tab that I am filling with data from my DB, I would like to change the color of the header text on the tab if that bulleted list contains information (to draw the users attention to the tab).  I can't seem to effect the color in my code behind function that I use to bind the data to the bulleted list...is there a way to make this happen?

DaveKan United States

11/25/2008 7:48:28 PM #

Damien White

DaveKan -
You can add HTML code in the headertext property, for example:
<ajaxtoolkit:tabpanel id="tab01" runat="server" headertext="<b>Tab 1</b>">
...
</ajaxtoolkit:tabpanel>


Hope this helps.  
-Damien

Damien White United States

12/1/2008 7:53:27 AM #

Asim

Hi, Great Article,  Helped me alot, Thankyou very much, i m just stucked at a point, how to reduce the gap or spacing between tabs, please help me out,



Asim.

Asim U.A.E.

12/1/2008 9:42:32 AM #

Damien White

Asim -
To reduce the spacing, just add a negative margin-right to ajax__tab_outer . For example:

.visoft__tab_xpie7 .ajax__tab_outer {
     height:29px;
     margin-right:-1px;
}

And obviously a positive right margin would space them out more.

If you are talking about the padding of the tab, then that is actually part of the image, so you would need to change the image sizes and then adjust the padding accordingly.

-Damien

Damien White United States

12/2/2008 4:25:10 AM #

Asim

Thanks a lot Damien for the prompt response, i will try it in a while and will get back to you i need any further help.


Thank You,

Asim.

Asim U.A.E.

12/2/2008 5:31:28 AM #

Asim

Thank you Damien, it worked like a bomb.


Asim.

Asim U.A.E.

12/16/2008 3:44:58 PM #

Pacman429

Thank you for a great explanation on styling the Tab Control.

I have run into a problem when attempting to change the color of the text when hovering over a tab.  Everything works fine until you attempt to hover over the active table.  The text changes and I want to leave the color alone.  Could you please offer any suggestions?

/* XP IE7 theme - Backgrounds */
.Control__tab_Application .ajax__tab_outer      { background:url(./../image/unselected_right.jpg) no-repeat right; }
.Control__tab_Application .ajax__tab_inner      { background:url(./../image/unselected_left.jpg) no-repeat; }
.Control__tab_Application .ajax__tab_tab      { background:url(./../image/unselected_middle.jpg) repeat-x; }
.Control__tab_Application .ajax__tab_active .ajax__tab_outer  { background:url(./../image/selected_right.jpg) no-repeat right; }
.Control__tab_Application .ajax__tab_active .ajax__tab_inner  { background:url(./../image/selected_left.jpg) no-repeat; }
.Control__tab_Application .ajax__tab_active .ajax__tab_tab  { background:url(./../image/selected_middle.jpg) repeat-x; }

/* XP IE7 theme - Other Styles */
.Control__tab_Application .ajax__tab_header    font-family:verdana,tahoma,helvetica; color: White; font-weight: bold; font-size:12px;}
.Control__tab_Application .ajax__tab_outer   { height:21px; margin-right: 1px }
.Control__tab_Application .ajax__tab_inner   { padding-left: 7px; }
.Control__tab_Application .ajax__tab_tab   { padding:4px 20px;margin: 0; }
.Control__tab_Application .ajax__tab_hover    { font-family:verdana,tahoma,helvetica; color: #5D7239; font-weight: bold; font-size:12px;}
.Control__tab_Application .ajax__tab_body   { font-family:verdana,tahoma,helvetica;font-size:10pt;border:1px solid #999999;border-top:0;padding:3px;background-color:#ffffff; }

Pacman429 United States

12/16/2008 8:29:44 PM #

Damien White

Pacman429 -

Not sure I understand your issue, but it looks like your problem is with your hover style. Try just something like:

.Control__tab_Application .ajax__tab_hover { color: #5D7239; }

-Damien

Damien White United States

1/20/2009 2:01:35 PM #

trackback

Trackback from ASP.NET AJAX Forum Posts

colorful ajax tabs css

ASP.NET AJAX Forum Posts

2/4/2009 9:54:23 AM #

Faisal

Awesome Smile

Faisal Portugal

4/7/2009 11:07:40 AM #

atconway

This works great, thank you.  I only have 1 question about the setup.  I now have the following (any url line for example) as instructed in my .css:

background:url(../Images/AJAX Tabs/tab-hover-right.gif) no-repeat right;

The problem is, when I hover over the tab there is a quick flicker on the screen.  While looking in the footer of IE you can briefly see that the image is being downloaded (it is really quick), but the download still makes a quick flicker.

The default .css from the AJAX toolkit was as follows:

background:url(<%=WebResource("AjaxControlToolkit.Tabs.tab-hover-right.gif")%>) no-repeat right;

For whatever reason thier version does not flicker when hovering over the tabs.

Does anyone know of a way to prevent this flickering from downloading of the image?

Thank you,

atconway United States

4/7/2009 11:29:58 AM #

Damien White

@atconway -
Preload the hover images in order to eliminate the flicker. For example, try using this approach: www.maratz.com/.../

-Damien

Damien White United States

4/8/2009 6:49:01 PM #

james popielarz

Great Job Save me big time..........

james popielarz United States

4/9/2009 9:38:28 AM #

Steve

Very useful, thanks.

I was trying to use the defaults for the tab control, and found two problems/bugs - one is a white border round the active tab, and the other a gap or whitespace in the middle of the tabs (when modifying the tabs with your own CSS, similar to what you have done in this post).  

This post provides an explanation & solution for both problems:

www.appetere.com/.../...CSS___layout_problems.aspx

Steve United Kingdom

4/22/2009 5:03:29 PM #

Mike J.

I'm trying to make the tab sides wider than the default XP style.  The tab-right.gif is 4px and the tab-left.gif is 3px.  When I change:

.property_name .ajax__tab_inner { padding-left:3px }

and make it 4px or more, the gap appears in the tab even when I make the tab-left.gif wider to match.

What do I need to do for a wider side?  I need to make a angle shaped tab.

Thanks!

Mike J. United States

4/22/2009 6:38:59 PM #

Damien White

@Mike J. -

That should work fine.  As long as your images is as wide as the padding, there shouldn't be a gap.  My guess is that something else may be causing the issue.

-Damien

Damien White United States

5/21/2009 4:39:17 PM #

Joseph

This helped a ton. Thanks!

Joseph United States

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading