【发布时间】: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> </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 找到了问题.. 我有一个
codethis.MultiPurposePanel.Visible = false;code每次回发都会触发,因此标签消失了。无论如何,谢谢伙计:-)!
标签: jquery asp.net tabs updatepanel web-parts