简体   繁体   English

在ASP.NET中设置活动选项卡Ajax TabContainer会导致整个容器消失

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

I have an ASP.NET page that uses the ASP.NET Ajax Control Toolkit TabContainer . 我有一个ASP.NET页面,它使用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. Page_Load事件中,我隐藏了一些基于给予页面的数据的选项卡。 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. 如果我使用tabIndex查询字符串参数设置点击页面,则整个选项卡容器将消失。

The strange thing is that if I change LoadDataIntoTabs() to not hide tabs that contain no data, everything works as you would expect (ie the correct tab is selected when the page renders). 奇怪的是,如果我将LoadDataIntoTabs()更改为隐藏包含数据的选项卡,则一切都按预期工作(即在页面呈现时选择正确的选项卡)。

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

Try to set the desired tab via ActiveTab like: 尝试通过ActiveTab设置所需的选项卡,如:

ctlTabContainer.ActiveTab = tbpPendingWidgets;

If you set the first tab to Visible=false then you have to set the next visible tab page via ActiveTab. 如果将第一个选项卡设置为Visible=false则必须通过ActiveTab设置下一个可见选项卡页面。

I'am using the AjaxControlToolkit Release 30930 (September 2009). 我正在使用AjaxControlToolkit Release 30930(2009年9月)。

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 . 在我没有尝试设置活动选项卡的另一种情况下,我不得不重置tabcontainer.ActiveTabIndex = 0

So I put the two together and it worked. 所以我把两者放在一起就行了。

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: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:TabPanel ID="tab1" runat="server" TabIndex="0"> //您的面板</cc1:TabPanel> <cc1:TabPanel ID="tab2" runat="server" TabIndex="1"> //你的面板</cc1:TabPanel>

</cc1:TabContainer>

write this code in cs page 在cs页面中编写此代码

TabContainer1.ActiveTabIndex = 1;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM