在 ASP.NET Ajax TabContainer 中设置活动选项卡会导致整个容器消失 [英] Setting active tab in ASP.NET Ajax TabContainer causes entire container to disappear

查看:14
本文介绍了在 ASP.NET Ajax TabContainer 中设置活动选项卡会导致整个容器消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 ASP.NET Ajax 的 ASP.NET 页面控制工具包 TabContainer.在 Page_Load 事件中,我根据提供给页面的数据隐藏了一些选项卡.然后,我想根据(可选)查询字符串参数的值激活其中一个选项卡.

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.

所以我有:

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 查询字符串参数集的页面,整​​个选项卡容器就会消失.

If I hit the page with the tabIndex query string parameter set, the entire tab container disappears.

奇怪的是,如果我将 LoadDataIntoTabs() 更改为 not 隐藏不包含数据的选项卡,则一切都如您所愿(即选择了正确的选项卡当页面呈现时).

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

有什么想法吗?

编辑

根据要求,这里有更多详细信息:

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

推荐答案

尝试通过 ActiveTab 设置所需的选项卡,例如:

Try to set the desired tab via ActiveTab like:

ctlTabContainer.ActiveTab = tbpPendingWidgets;

如果您将第一个选项卡设置为 Visible=false,那么您必须通过 ActiveTab 设置下一个可见的选项卡页面.

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

我使用的是 AjaxControlToolkit 版本 30930(2009 年 9 月).

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

这篇关于在 ASP.NET Ajax TabContainer 中设置活动选项卡会导致整个容器消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆