[英]Components in AJAX tab not showing up when switching tab
我试图隐藏并显示从SQL中获得的某些条件的AJAX选项卡面板。 假设我有三个标签,第一个标签始终存在,第二个标签仅在尚未交付时显示,而第三个标签仅在交付时显示。 这是我切换标签以获取标签索引的方法:
protected void Page_Load(object sender, EventArgs e)
{
//Get distributionID based on URL
distributionID = Request.QueryString["id"];
//First tab to display beneficiary details
beneficiaryIndv = packBLL.getBeneficiaryDetail(distributionID);
if (IsPostBack)
{
//Get the index of selected tab
if (!(ViewState["TabIndex"] == null) && (!(sender == null)))
{
if (sender.GetType().ToString().Equals("AjaxControlToolkit.TabContainer"))
{
((AjaxControlToolkit.TabContainer)sender).ActiveTabIndex = (int)ViewState["TabIndex"];
}
}
}
//On page load to check the delivery status to determine which tab to hide
string isDelivered = packBLL.checkIsDelivered(distributionID);
if (isDelivered == "Y")
{
TabPanelSPU.Visible = false;
}
else
{
TabPanelViewSPUItem.Visible = false;
}
}
protected void TabContainer_OnActiveTabChanged(object sender, EventArgs e)
{
ViewState["TabIndex"] = TabContainer.ActiveTabIndex;
if ((int)ViewState["TabIndex"] == 1)
{
//Get the list of standard packing unit by distribution
List<DistributionStandardPackingUnits> SPUList = new List<DistributionStandardPackingUnits>();
SPUList = packBLL.getAllDistSPUByDistID(distributionID);
gvSPU1.DataSource = SPUList;
gvSPU1.DataBind();
}
else if ((int)ViewState["TabIndex"] == 2)
{
//Get the list of standard packing unit by distribution
List<DistributionStandardPackingUnits> SPUList = new List<DistributionStandardPackingUnits>();
SPUList = packBLL.getAllDistSPUByDistID(distributionID);
gvSPU.DataSource = SPUList;
gvSPU.DataBind();
}
}
但是,在交付状态被交付时,它会隐藏第二个选项卡。 但是第三个选项卡中的组件未显示。 我不知道是因为活动更改方法的选项卡中的if else语句导致此问题吗?
提前致谢。
编辑
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:TabContainer ID="TabContainer" runat="server" ActiveTabIndex="0"
OnActiveTabChanged="TabContainer_OnActiveTabChanged" AutoPostBack="true">
<!--FIRST TAB -->
<asp:TabPanel ID="TabPanelBeneficiary" runat="server" HeaderText="Beneficiary" CssClass="ajax__tab_tab">
<ContentTemplate>
<h3 class="form-section">Person Info</h3>
<h3 class="form-section">Address</h3>
</ContentTemplate>
</asp:TabPanel>
<!--SECOND TAB -->
<asp:TabPanel ID="TabPanelSPU" runat="server" HeaderText="Standard Packing" CssClass="ajax__tab_tab">
<ContentTemplate>
</ContentTemplate>
</div>
</div>
</ContentTemplate>
</asp:TabPanel>
<!--THIRD TAB -->
<asp:TabPanel ID="TabPanelViewSPUItem" runat="server" HeaderText="Distributed Packing Items" CssClass="ajax__tab_tab">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
问题是TabContainer.ActiveTabIndex
将跳过隐藏的选项卡。 如果将TabPanelSPU.Visible
设置为false,则在单击TabPanelViewSPUItem
(第三个选项卡)时, TabContainer.ActiveTabIndex
的值将为1而不是2。这说明了为什么不显示第三个选项卡中的组件。
我建议改为检查TabPanelSPU.Visible
和TabPanelViewSPUItem.Visible
protected void TabContainer_OnActiveTabChanged(object sender, EventArgs e)
{
if (TabPanelSPU.Visible)
{
//Get the list of standard packing unit by distribution
List<DistributionStandardPackingUnits> SPUList = new List<DistributionStandardPackingUnits>();
SPUList = packBLL.getAllDistSPUByDistID(distributionID);
gvSPU1.DataSource = SPUList;
gvSPU1.DataBind();
}
if (TabPanelViewSPUItem.Visible)
{
//Get the list of standard packing unit by distribution
List<DistributionStandardPackingUnits> SPUList = new List<DistributionStandardPackingUnits>();
SPUList = packBLL.getAllDistSPUByDistID(distributionID);
gvSPU.DataSource = SPUList;
gvSPU.DataBind();
}
}
您还需要删除Page_Load
中的这部分代码,因为不需要。
if (IsPostBack)
{
//Get the index of selected tab
if (!(ViewState["TabIndex"] == null) && (!(sender == null)))
{
if (sender.GetType().ToString().Equals("AjaxControlToolkit.TabContainer"))
{
((AjaxControlToolkit.TabContainer)sender).ActiveTabIndex = (int)ViewState["TabIndex"];
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.