AjaxControlToolkit TabContainer: TabPanel.Visible='False' should not display header text
If you set the visible property of TabPanels within your TabContainer to false, it still shows the Header Text in the page when rendered. What should happen is any TabPanels with Visible set to False should be hidden. A fix for this has been posted to the AJAX Control Toolkits Issue Tracker, but we have to wait for the next release to get the fix in place.
Is there a work around?
Below is an Inherited class I created using the fix described to allow me to fix this issue myself until the next release.
public class FixedTabContainer : AjaxControlToolkit.TabContainer { protected override void RenderHeader(HtmlTextWriter writer) { foreach (TabPanel panel in Tabs) { if (panel.Visible) //added this line panel.RenderHeader(writer); } } }
Well, actually, the above code doesn’t work!
**Compiler Error Message: **CS0122: ‘AjaxControlToolkit.TabPanel.RenderHeader(System.Web.UI.HtmlTextWriter)’ is inaccessible due to its protection level
I then tried to Inherit from the AjaxControlToolkit.TabPanel class within my namespace, but that doesn’t get around the protection level of the RenderHeader method.
Conclusion
Basically, the only way to fix this before the next release comes (that is assuming they put the fix in the next release) is to implement this fix in the toolkit’s source code yourself and then compiling it in. This is actually something I don’t like to do just in case I make some change to the toolkit manually and then forget to carry that over when upgrading to the latest version when it comes out, but it is nice you have the ability to do is since the AJAX Control Toolkit is Open Source.
UPDATE: Here’s a rather easy workaround that I found to this issue… You just set Visible to False and set the HeaderText to a blank string if you don’t want the TabPanel to be shown. This worked perfectly in the instance I needed it to work. Below is a simplified version of what I did.
«/span>ajaxToolkit:TabPanel runat=”server” ID=”tabPeople” Visible=’<%# ShouldBeShow() %>’ HeaderText=’<%# ShouldBeShow() ? “People” : “” %>’>