【发布时间】:2012-02-09 12:32:44
【问题描述】:
这是我的情况:
页面:
<asp:UpdatePanel ID="updatePanel1" runat="server" ChildrenAsTriggers="true">
<ContentTemplate>
...
<uc:ChildControl ID="ucChild" runat="server" />
...
</ContentTemplate>
</asp:UpdatePanel>
儿童控制:
...
<asp:DropDownList id="dropDown1" runat="server" />
...
当 ChildControl 中 DropDownList 的选择发生变化时,我想(异步)更新 Page 中的 UpdatePanel。我尝试了 AutoPostBack="true",但这总是会导致页面的完整 PostBack(请参阅 this question)。
我尝试使用
<Triggers>
<asp:AsyncPostBackTrigger ControlID="???" EventName="SelectedIndexChanged" />
</Triggers>
但“dropDown1”和“ucChild.dropDown1”都不能用作 ControlID 的值。
我还尝试将 UpdatePanel 的引用传递给 ChildControl 并通过以下方式添加触发器:
protected override void OnPreRender(EventArgs e)
{
if (ParentUpdatePanel != null)
{
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = dropDown1.ID;
trigger.EventName = "SelectedIndexChanged";
ParentUpdatePanel.Triggers.Add(trigger);
}
base.OnPreRender(e);
}
(也尝试使用 dropDown1.ChildID)
但是当下拉列表中的值更改时,我仍然无法触发 UpdatePanel。问题似乎是 UpdatePanel 看不到 ChildControl 中的 Control,因此无法相应地设置 Trigger。
我该怎么做?
【问题讨论】:
标签: c# asp.net ajax drop-down-menu updatepanel