【问题标题】:jQuery Tabs not showing the Asp Panel inside the selected Tab on PostBackjQuery 选项卡未在 PostBack 上的选定选项卡内显示 Asp 面板
【发布时间】:2014-07-14 10:51:17
【问题描述】:

故事是这样的:

我有 2 个更新面板。 UpdatePanel 1 有一个下拉列表,它有自己的功能。 UpdatePanel2 具有用于 jQuery 选项卡功能的 Div。

这里是sn-ps的代码:

ASPX

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <table style="width: 100%;">
            <tr>
                <td class="LabelColumn">
                    <asp:Label ID="Label11" runat="server" Text="Company"></asp:Label>
                </td>
                <td>
                    <asp:DropDownList ID="CompanyDropDownList" runat="server" Width="300px" OnSelectedIndexChanged="CompanyDropDownList_SelectedIndexChanged" AutoPostBack="True">
                    </asp:DropDownList>
                </td>
                <td>&nbsp;</td>
            </tr>
        </table>
    </ContentTemplate>
</asp:UpdatePanel>

<asp:UpdatePanel ID="UpdatePanel2" runat="server">
    <ContentTemplate>
        <div id="tabs">
            <ul style="width: 200px">
                <li><a href="#MultiPurposeForm">Multi Purpose Form</a></li>
                <li><a href="#LeaveApplicationForm">Application For Leave</a></li>
            </ul>

            <div id="MultiPurposeForm">
                <table>
                    <tr>
                        <td class="auto-style3">
                            <asp:Label ID="LabelHeader" runat="server" Text="Multi Purpose Form"></asp:Label>

                            <asp:Panel ID="MultiPurposeFormPanel" runat="server" Visible="True" OnLoad="MultiPurposeFormPanel_Load1">
                                <!-- Many controls come here -->
                            </asp:Panel>
                        </td>
                    </tr>
                </table>
            </div>

            <div id="LeaveApplicationForm">
                <asp:Label ID="Label4" runat="server" Text="Application for Leave"></asp:Label>
            </div>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

Javascript

<script type="text/javascript">

    function pageLoad(sender, args)
    {
        $(document).ready(function () {
            $("#tabs").tabs();
            //$("#dialog").dialog();
        });
    }

</script>

代码背后

protected void CompanyDropDownList_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.ClearEmployeeDetails(true);
            this.ListEmployeesCheckBox.Checked = false;
            this.EmployeeSelectionDropDownList.Visible = false;

            if (this.CheckLoggedInUserForHRCoordinator())
            {
                this.ListEmployeesCheckBox.Enabled = true;
            }
            else
            {
                this.ListEmployeesCheckBox.Enabled = false;
                this.EmployeeSelectionDropDownList.Visible = false;
            }
        }


protected void MultiPurposeFormPanel_Load1(object sender, EventArgs e)
        {
            this.PopulateMPDocumentCategories();
        }

        private void PopulateMPDocumentCategories()
        {
            if (this.MPDocumentCategoryDropDownList.Items.Count == 0)
            {
                MultiPurposeDocumentEntityService documentService =
                new MultiPurposeDocumentEntityService();

                MultiPurposeDocumentCollection documentCollection =
                    documentService.GetAll();

                foreach (var document in documentCollection)
                {
                    this.MPDocumentCategoryDropDownList.Items.Add(new ListItem(document.Title,
                        document.Id.ToString()));
                }

                if (this.MPDocumentCategoryDropDownList.Items.Count != 0)
                {
                    this.PopulateMPDocumentList(this.MPDocumentCategoryDropDownList.SelectedItem.Text);
                }
            }
        }

第一次加载页面时,一切正常。但是,在 UpdatePanel1 的下拉列表中选择一个项目后,我无法看到 MultiPurposeFormPanel。我只能看到LabelHeader。

知道为什么会这样吗?

【问题讨论】:

  • 看起来你在做正确的事,使用 pageLoad 重新初始化选项卡控件.. 你也可以发布代码隐藏吗?
  • @sh1rts 您好,我已经发布了后面的代码。如果您还需要其他内容,请告诉我。后面的代码只是在下拉列表中添加了一些项目。
  • 嗯,我觉得还可以吗?你能做两件事吗 - 1) 在你的 pageLoad() 函数中放置一个警报或一个 console.log('hello'),然后 2) 打开你的浏览器的调试器,看看控制台和网络跟踪中发生了什么,当您在 CompanyDropDown 中选择一个项目时。你看到了什么?
  • @sh1rts 找到了问题.. 我有一个code this.MultiPurposePanel.Visible = false; code 每次回发都会触发,因此标签消失了。无论如何,谢谢伙计:-)!

标签: jquery asp.net tabs updatepanel web-parts


【解决方案1】:

每次回发都有一个可见的 = false 触发器。抱歉耽误您的时间。

【讨论】:

  • 呵呵 :) 不用担心,伙计,有时您只有在尝试向互联网上的一些随机的家伙解释您的代码后才能看到答案 :)
  • @sh1rts 嘿嘿,我猜是真的:-)!
猜你喜欢
  • 2019-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多