在ASP.NET AJAX TabContainer的设置活动标签会导致整个容器消失 [英] Setting active tab in ASP.NET Ajax TabContainer causes entire container to disappear

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

问题描述

我有一个使用 ASP.NET AJAX的ASP.NET页面控制工具包TabContainer的的。在的Page_Load 事件,我隐藏一些基于给定的页面数据的选项卡。然后,我希望能够基于一个可选的查询字符串参数的值激活的标签之一。

所以我有:

 保护无效的Page_Load(对象发件人,EventArgs的发送)
{
    如果(!this.IsPostBack)
    {
        //没有数据标签都藏在这里
        LoadDataIntoTabs();        preselectCorrectTab();
    }
}私人无效preselectCorrectTab()
{
    如果(ctlTabContainer.Visible)
    {
        如果(!string.IsNullOrEmpty(的Request.QueryString [的tabIndex]))
        {
            INT的tabIndex = 0;            如果(int.TryParse(的Request.QueryString [的tabIndex],出来的tabIndex))
            {
                如果((ctlTabContainer.Tabs.Count>的tabIndex)及&放大器; ctlTabContainer.Tabs [的tabIndex]。可见)
                {
                    ctlTabContainer.ActiveTabIndex =的tabIndex;
                }
            }
        }
    }
}

如果我打的的tabIndex 查询字符串参数设置页面,整个标签的容器中消失。

但奇怪的是,如果我换 LoadDataIntoTabs()不可以不包含任何数据隐藏的标签,一切都按你所期望(即页面呈现时,正确的选项卡中选择)。

任何想法?


修改

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

 私人无效LoadDataIntoTabs()
{
    LoadPendingWidgetsTab();
    LoadDataIntoTab2();
    LoadDataIntoTab3();
    //等等...
}私人无效LoadPendingWidgetsTab()
{
    IList的<窗​​口小部件> pendingWidgets = GetAllPendingWidgets();    如果((pendingWidgets = NULL)及!及(pendingWidgets.Count大于0))
    {
        tbpPendingWidgets.Visible = TRUE;
        tbpPendingWidgets.HeaderText =的String.Format(待小工具({0}),pendingWidgets.Count);        grdPendingWidgets.DataSource = pendingWidgets;
        grdPendingWidgets.DataBind();
    }
    其他
    {
        tbpPendingWidgets.Visible = FALSE;
    }
}


解决方案

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

ctlTabContainer.ActiveTab = tbpPendingWidgets;

如果您设置第一个选项卡可见=假,那么你必须通过ActiveTab设置下一个可见的标签页。

使用AjaxControlToolkit发行30930(2009年9月)我'。

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

解决方案

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

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

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