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; } }
source share