title: Setting active tab in ASP.NET Ajax TabContainer causes entire container to disappear
body: <p>I have an ASP.NET page that uses the <a href="http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Tabs/Tabs.aspx" rel="noreferrer">ASP.NET Ajax Control Toolkit TabContainer</a>. In the <code>Page_Load</code> event, I am hiding some of the tabs based on the data given to the page. I then want to make one of the tabs active based on the value of an (optional) query string parameter.</p>
  
  <p>So I have:</p>
  
  <pre><code>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 &gt; tabIndex ) &amp;&amp; ctlTabContainer.Tabs[ tabIndex ].Visible )
                  {
                      ctlTabContainer.ActiveTabIndex = tabIndex;
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>If I hit the page with the <code>tabIndex</code> query string parameter set, the entire tab container disappears. </p>
  
  <p>The strange thing is that if I change <code>LoadDataIntoTabs()</code> to <strong>not</strong> hide tabs that contain no data, everything works as you would expect (i.e. the correct tab is selected when the page renders).</p>
  
  <p>Any ideas?</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>As requested, here are more details:</p>
  
  <pre><code>private void LoadDataIntoTabs ()
  {
      LoadPendingWidgetsTab();
      LoadDataIntoTab2();
      LoadDataIntoTab3();
      // etc...
  }
  
  private void LoadPendingWidgetsTab ()
  {
      IList&lt;Widget&gt; pendingWidgets = GetAllPendingWidgets();
  
      if ( ( pendingWidgets != null ) &amp;&amp; ( pendingWidgets.Count &gt; 0 ) )
      {
          tbpPendingWidgets.Visible = true;
          tbpPendingWidgets.HeaderText = String.Format( "Pending Widgets ({0})", pendingWidgets.Count );
  
          grdPendingWidgets.DataSource = pendingWidgets;
          grdPendingWidgets.DataBind();
      }
      else
      {
          tbpPendingWidgets.Visible = false;
      }
  }
  </code></pre>