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

 ̄綄美尐妖づ 提交于 2019-12-04 01:38:50

问题


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

回答1:


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).




回答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.




回答3:


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;



来源:https://stackoverflow.com/questions/811657/setting-active-tab-in-asp-net-ajax-tabcontainer-causes-entire-container-to-disap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!