由控制是在不同的ContentPlaceHolder触发的UpdatePanel的更新 [英] Trigger an update of the UpdatePanel by a control that is in different ContentPlaceHolder

查看:201
本文介绍了由控制是在不同的ContentPlaceHolder触发的UpdatePanel的更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个ContentPlaceHolders页面。其中有一个下拉列表和其它的UpdatePanel与内容。

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

我如何可以触发通过下拉的selectedItemChanged事件更新的UpdatePanel的,当他们在不同的ContentPlaceholders?

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

下面,因为UpdatePanel1是行不通的不知道DropDown1:

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>

的一种方法是使一个将由JavaScript的页面上下拉时的项目被选择被称为Ajax页面方法。然后在后面的code,里面那个页面的方法,调用UpdatePanel1.Update()。

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?

推荐答案

从<一个href="http://msdn.microsoft.com/en-us/library/system.web.ui.asyncpostbacktrigger.aspx">http://msdn.microsoft.com/en-us/library/system.web.ui.asyncpostbacktrigger.aspx

控制的   AsyncPostBackTrigger引用必须   在相同的命名容器   更新面板的量是一个   触发。是基于触发器   在其他命名容器控件   不支持。

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.

解决方法是使用控制了的UniqueID 触发器所引用。不幸的是,UniqueID的资格都没有 直到控制已被添加到它的父(和它的父 已被添加到它的父,一路控制树)。

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).

在你的code后面,试试:

In your code behind, try:

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

这篇关于由控制是在不同的ContentPlaceHolder触发的UpdatePanel的更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆