通过位于不同 ContentPlaceHolder 中的控件触发 UpdatePanel 的更新

发布于 2024-07-11 11:51:44 字数 777 浏览 6 评论 0原文

我有一个包含两个 ContentPlaceHolders 的页面。 其中一个有一个 DropDown,另一个包含内容的 UpdatePanel。

当 DropDown 的 selectedItemChanged 事件位于不同的 ContentPlaceholder 中时,如何触发对 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>

一种方法是创建一个 ajax 页面方法,当选择 DropDown 的项目时,该方法将由页面上的 javascript 调用。 然后在后面的代码中,在该页面方法内,调用 UpdatePanel1.Update()。

有更简单的选择吗?

I have a page with two ContentPlaceHolders. One has a DropDown and another UpdatePanel with content.

How can I trigger update to the UpdatePanel by the DropDown's selectedItemChanged event when they are in different ContentPlaceholders?

The following would not work since UpdatePanel1 doesn't know about 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. Then in code behind, inside that page method, call UpdatePanel1.Update().

Is there an easier alternative?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萧瑟寒风 2024-07-18 11:51:44

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

该控件
AsyncPostBackTrigger 引用必须
位于同一个命名容器中
它所属的更新面板
扳机。 触发器基于
其他命名容器中的控件
不支持。

解决方法是使用该控件的 UniqueID
触发器正在引用。 不幸的是,UniqueID 不合格
直到该控件已添加到其父级(及其父级
已添加到其父级,一直到控制树)。

在你的代码后面,尝试:

UpdatePanel1.Triggers.Add(new AsyncPostBackTrigger()
{
    ControlID = DropDown1.UniqueID,
    EventName = "SelectedIndexChanged", // this may be optional
});

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

The control that the
AsyncPostBackTrigger references must
be in the same naming container as
the update panel for which it is a
trigger. Triggers that are based on
controls in other naming containers
are not supported.

The workaround is to use the UniqueID of the control that the
trigger is referencing. Unfortunately the UniqueID isn't qualified
until the control has been added to its parent (and its parent
has been added to its parent, all the way up the control tree).

In your code behind, try:

UpdatePanel1.Triggers.Add(new AsyncPostBackTrigger()
{
    ControlID = DropDown1.UniqueID,
    EventName = "SelectedIndexChanged", // this may be optional
});
蓝天白云 2024-07-18 11:51:44

在代码隐藏文件中,您应该能够执行以下操作:

ScriptManager.RegisterAsyncPostBackControl(dropdown1);

In the code-behind file, you should be able to do:

ScriptManager.RegisterAsyncPostBackControl(dropdown1);
一笑百媚生 2024-07-18 11:51:44

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

You can enforce update any of page UpdatePanels by call updatePanel1.Update() method on server side.
For example during update updatePanel1 on button1.Click call updatePanel2.Update() and both panels will be updated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文