我有一个使用 ASP.NET Ajax的ASP.NET页面Control Toolkit TabContainer 。在Page_Load事件中,我根据给予页面的数据隐藏了一些选项卡。然后,我想根据(可选)查询字符串参数的值使其中一个选项卡处于活动状态。

所以我有:

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

如果我使用tabIndex查询字符串参数集点击页面,则整个选项卡容器将消失。

奇怪的是,如果我将LoadDataIntoTabs()更改为而不是隐藏不包含数据的标签,一切都会按预期工作(即在页面呈现时选择正确的标签)。

有什么想法吗?


修改

根据要求,这里有更多细节:

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;
    }
}
有帮助吗?

解决方案

尝试通过ActiveTab设置所需的标签,如:

ctlTabContainer.ActiveTab = tbpPendingWidgets;

如果您将第一个标签设置为Visible=false,则必须通过ActiveTab设置下一个可见标签页。

我使用的是AjaxControlToolkit Release 30930(2009年9月)。

其他提示

这对我有用:
手动重置索引,可见性和活动选项卡。

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

在我没有尝试设置活动标签的另一种情况下,我不得不重置tabcontainer.ActiveTabIndex = 0

所以我把两者放在一起就行了。

这很简单,工作得很完美,试试这个

为选项卡容器中使用的每个选项卡分配选项卡索引,如....

然后<cc1:TabContainer ID="TabContainer1" runat="server">

<cc1:TabPanel ID="tab1" runat="server" TabIndex="0"> //你的小组 </cc1:TabPanel> <cc1:TabPanel ID="tab2" runat="server" TabIndex="1"> //你的小组 </cc1:TabContainer>

TabContainer1.ActiveTabIndex = 1;

在cs页面中编写此代码

<=>

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top