ASP.NET에서 활성 탭 설정 AJAX TABCONTAINER 전체 컨테이너가 사라집니다.
-
03-07-2019 - |
문제
ASP.NET 페이지가 있습니다 ASP.NET AJAX 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 릴리스 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:TabPanel>
</cc1:TabContainer>
이 코드를 CS 페이지에 작성하십시오
TabContainer1.ActiveTabIndex = 1;