Setting active tab in ASP.NET Ajax TabContainer causes entire container to disappear
Asked Answered
C

3

5

I have an ASP.NET page that uses the ASP.NET Ajax Control Toolkit TabContainer. In the Page_Load 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.

So I have:

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 the page with the tabIndex query string parameter set, the entire tab container disappears.

The strange thing is that if I change LoadDataIntoTabs() to not hide tabs that contain no data, everything works as you would expect (i.e. the correct tab is selected when the page renders).

Any ideas?


EDIT

As requested, here are more details:

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;
    }
}
Commercialism answered 1/5, 2009 at 14:40 Comment(1)
Can you post the code for LoadDataIntoTabs(), it sounds like the issue is in thereFerocious
T
7

Try to set the desired tab via ActiveTab like:

ctlTabContainer.ActiveTab = tbpPendingWidgets;

If you set the first tab to Visible=false then you have to set the next visible tab page via ActiveTab.

I'am using the AjaxControlToolkit Release 30930 (September 2009).

Theodore answered 10/3, 2010 at 15:39 Comment(1)
This fixed my issue. It looks like if your 'ActiveTab' is made invisible it makes the whole tab container hidden.Shaniqua
P
2

This worked for me:
Manually resetting the index, the visibility and the active tab.

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

In another situation where I was not trying to set the active tab, I had to reset tabcontainer.ActiveTabIndex = 0.

So I put the two together and it worked.

Pabulum answered 12/4, 2011 at 15:38 Comment(0)
S
0

this is simple and worked perfectly,try this

assign the tab index for every tab that are used in your tab container like....

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 in cs page

TabContainer1.ActiveTabIndex = 1;

Subcutaneous answered 12/9, 2013 at 6:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.