通过位于不同 ContentPlaceHolder 中的控件触发 UpdatePanel 的更新
我有一个包含两个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自 http://msdn.microsoft.com/en-我们/library/system.web.ui.asyncpostbacktrigger.aspx
解决方法是使用该控件的 UniqueID
触发器正在引用。 不幸的是,UniqueID 不合格
直到该控件已添加到其父级(及其父级
已添加到其父级,一直到控制树)。
在你的代码后面,尝试:
From http://msdn.microsoft.com/en-us/library/system.web.ui.asyncpostbacktrigger.aspx
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:
在代码隐藏文件中,您应该能够执行以下操作:
In the code-behind file, you should be able to do:
您可以通过调用服务器端的
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
callupdatePanel2.Update()
and both panels will be updated.