Setting an active tab in ASP.NET Ajax TabContainer causes the entire container to disappear

I have an ASP.NET page that uses the ASP.NET Ajax Control Toolkit TabContainer . In the Page_Load event, I hide some tabs based on the data presented on the page. Then I want to activate one of the tabs based on the value of the (optional) string query parameter.

So, I have a:

 protected void Page_Load ( object sender, EventArgs e ) { if ( !this.IsPostBack ) { // Tabs with no data are hidden in here LoadDataIntoTabs(); PreselectCorrectTab(); } } private void PreselectCorrectTab () { if ( ctlTabContainer.Visible ) { if ( !string.IsNullOrEmpty( Request.QueryString[ "tabIndex" ] ) ) { int tabIndex = 0; if ( int.TryParse( Request.QueryString[ "tabIndex" ], out tabIndex ) ) { if ( ( ctlTabContainer.Tabs.Count > tabIndex ) && ctlTabContainer.Tabs[ tabIndex ].Visible ) { ctlTabContainer.ActiveTabIndex = tabIndex; } } } } } 

If I hit a page with the tabIndex query string parameter, the entire tab container will disappear.

It is strange that if I changed LoadDataIntoTabs() to non- hidden tabs that do not contain data, everything will work as you would expect (i.e. the correct tab will be selected when the page is displayed).

Any ideas?


EDIT

In accordance with the request for more information:

 private void LoadDataIntoTabs () { LoadPendingWidgetsTab(); LoadDataIntoTab2(); LoadDataIntoTab3(); // etc... } private void LoadPendingWidgetsTab () { IList<Widget> pendingWidgets = GetAllPendingWidgets(); if ( ( pendingWidgets != null ) && ( pendingWidgets.Count > 0 ) ) { tbpPendingWidgets.Visible = true; tbpPendingWidgets.HeaderText = String.Format( "Pending Widgets ({0})", pendingWidgets.Count ); grdPendingWidgets.DataSource = pendingWidgets; grdPendingWidgets.DataBind(); } else { tbpPendingWidgets.Visible = false; } } 
+4
source share
3 answers

Try setting the desired tab using ActiveTab, for example:

ctlTabContainer.ActiveTab = tbpPendingWidgets;

If you set the first tab to Visible=false , you need to set the next visible tab through ActiveTab.

I am using AjaxControlToolkit Release 30930 (September 2009).

+6
source

This worked for me:
Manual reset of index, visibility and active tab.

  tabcontainer.ActiveTab = tabname tabcontainer.Visible = True tabcontainer.ActiveTabIndex = 2 

In another situation, when I did not try to set the active tab, I had to reset tabcontainer.ActiveTabIndex = 0 .

So I put them together, and it worked.

+1
source

it's simple and works great, try this

assign a tab index for each tab that is used in your tab container, for example ....

then <cc1:TabContainer ID="TabContainer1" runat="server">

<cc1:TabPanel ID="tab1" runat="server" TabIndex="0"> // your panel </cc1:TabPanel> <cc1:TabPanel ID="tab2" runat="server" TabIndex="1"> // your panel </cc1:TabPanel>

</cc1:TabContainer>

write this code on the cs page

TabContainer1.ActiveTabIndex = 1;

0
source

All Articles