切换选项卡时,AJAX选项卡中的组件未显示

时间:2014-02-02 13:43:45

标签: c# asp.net ajax tabs

我试图隐藏并显示AJAX选项卡面板,其中包含我从SQL获得的某些条件。假设我有三个选项卡,第一个选项卡始终存在,第二个选项卡仅在尚未交付时显示,而第三个选项卡仅在交付时显示。这是我切换选项卡以获取选项卡索引的方法:

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>

1 个答案:

答案 0 :(得分:0)

问题是TabContainer.ActiveTabIndex会跳过隐藏的标签。如果您将TabPanelSPU.Visible设置为false,那么当您点击TabPanelViewSPUItem(第三个标签)时,TabContainer.ActiveTabIndex的值将为1而不是2.这就解释了为什么第三个标签内的组件没有显示。

我建议您检查TabPanelSPU.VisibleTabPanelViewSPUItem.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"];
        }
    }
}