15

我有一个包含两个 ContentPlaceHolders 的页面。一个有一个 DropDown 和另一个带有内容的 UpdatePanel。

当 DropDown 的 selectedItemChanged 事件位于不同的 ContentPlaceholders 中时,如何触发对 UpdatePanel 的更新?

由于 UpdatePanel1 不知道 DropDown1,因此以下操作不起作用:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"  ChildrenAsTriggers="true">
    <ContentTemplate>
        Some content that needs to be updated here...
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="DropDown1" EventName="SelectedIndexChanged" />
    </Triggers>
</asp:UpdatePanel>

One way is to make an ajax page method that would be called by javascript on the page when DropDown's item is selected. 然后在后面的代码中,在该页面方法中,调用 UpdatePanel1.Update()。

有没有更简单的选择?

4

3 回答 3

24

来自http://msdn.microsoft.com/en-us/library/system.web.ui.asyncpostbacktrigger.aspx

AsyncPostBackTrigger 引用的控件必须与作为触发器的更新面板位于同一命名容器中。不支持基于其他命名容器中的控件的触发器。

解决方法是使用触发器引用的控件的 UniqueID。不幸的是,直到控件被添加到它的父级(并且它的父级已经被添加到它的父级,一直到控件树),UniqueID 才被限定。

在您后面的代码中,尝试:

UpdatePanel1.Triggers.Add(new AsyncPostBackTrigger()
{
    ControlID = DropDown1.UniqueID,
    EventName = "SelectedIndexChanged", // this may be optional
});
于 2009-01-06T19:16:54.537 回答
3

在代码隐藏文件中,您应该能够:

ScriptManager.RegisterAsyncPostBackControl(dropdown1);
于 2009-01-06T17:08:47.947 回答
2

updatePanel1.Update()您可以通过服务器端的调用方法强制更新任何页面 UpdatePanel 。例如,在更新 updatePanel1 期间 ,两个面板都将被更新button1.ClickupdatePanel2.Update()

于 2011-05-05T16:41:43.053 回答