【发布时间】:2010-10-23 03:17:39
【问题描述】:
我有一个使用 ASP.NET Ajax Control Toolkit TabContainer 的 ASP.NET 页面。在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() 更改为 not 隐藏不包含数据的选项卡,一切都会按您的预期进行(即在页面呈现时选择了正确的选项卡)。
有什么想法吗?
编辑
根据要求,这里有更多详细信息:
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;
}
}
【问题讨论】:
-
你能把 LoadDataIntoTabs() 的代码贴出来吗,听起来问题出在那儿
标签: asp.net asp.net-ajax ajaxcontroltoolkit tabcontainer