UpdatePanel 和母版页中的两个内容占位符区域
我有一个“旧版”ASP.NET 网站,我想对其进行一些改进。我想做的一个领域是页面更新 - 目前,它始终是整页更新,但我想开始使用部分更新。
我希望能够使用 ASP.NET UpdatePanel
来实现此目的 - 但我对如何让它为我工作有点困惑。
我有一个母版页,它定义了多个内容占位符 - 简化后如下所示:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Default.master.cs" Inherits="WebForms_Default" %>
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>MyTitle</title>
</head>
<body>
<form id="myForm" runat="server">
<asp:ScriptManager ID="smgrMaster" runat="server" LoadScriptsBeforeUI="true">
<Scripts>
<asp:ScriptReference Path="~/Scripts/jquery-1.4.2.min.js" />
</Scripts>
</asp:ScriptManager>
<asp:ContentPlaceHolder runat="server" ID="cphSearch" />
<asp:ContentPlaceHolder runat="server" ID="cphContent" />
</form>
</body>
</html>
在我的内容页面上,我的网格显示 cphContent
区域内的数据 - 以及我的 cphSearch
区域我有许多输入控件 - 一个RadioButtonList 和两个DropDowns。目前,只要这些控件中的某些内容发生更改,就会发出回发(它们设置了 AutoPostback="true"
)。
我的问题是:如何告诉我的 UpdatePanel
(我试图将其包裹在 cphContent
区域中的网格)“监听”来自这三个控件的回发来自cphSearch
?
<asp:UpdatePanel>
<ContentTemplate>
<asp:GridView>
// grid view defined here
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID=".. what values to put here?? .." />
<asp:PostBackTrigger ControlID=".. - what values to put here?? .." />
</Triggers>
当我添加
时,我得到一个
部分,但是 cphSearch
内容区域中的那些控件是不可见,所以我想我无法真正将它们添加为更新触发器,对吗?
要么我完全不明白(绝对有可能!),要么我错过了一个明显的步骤/技巧来让它发挥作用——或者这是不可能的。让我知道!
I have a "legacy" ASP.NET site I'd like to improve a bit. One area I'd like to do something about is page updates - for now, it's always full page updates, but I'd like to start using partial updates.
I was hoping to be able to use the ASP.NET UpdatePanel
for this - but I'm a bit stuck on how to get this to work for me.
I have a master page which defines several content placeholders - simplified it looks like this:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Default.master.cs" Inherits="WebForms_Default" %>
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>MyTitle</title>
</head>
<body>
<form id="myForm" runat="server">
<asp:ScriptManager ID="smgrMaster" runat="server" LoadScriptsBeforeUI="true">
<Scripts>
<asp:ScriptReference Path="~/Scripts/jquery-1.4.2.min.js" />
</Scripts>
</asp:ScriptManager>
<asp:ContentPlaceHolder runat="server" ID="cphSearch" />
<asp:ContentPlaceHolder runat="server" ID="cphContent" />
</form>
</body>
</html>
On my content page, my grid is showing the data inside the cphContent
area - and in my cphSearch
area I have a number of input controls - a RadioButtonList
and two DropDowns
. Whenever something in those controls changes, for now, a postback is issued (they have AutoPostback="true"
set).
My problem is: how do I tell my UpdatePanel
(which I'm trying to wrap around my grid in the cphContent
area) to "listen" for postbacks from those three controls from cphSearch
?
<asp:UpdatePanel>
<ContentTemplate>
<asp:GridView>
// grid view defined here
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID=".. what values to put here?? .." />
<asp:PostBackTrigger ControlID=".. - what values to put here?? .." />
</Triggers>
When I add my <asp:UpdatePanel>
, I get a section <Triggers>
, but those controls in the cphSearch
content area aren't visible, so I guess I can't really add them as update triggers, correct?
Either I'm totally not getting it (absolutely possible!), or I'm missing an obvious step / trick to get this to work - or it's just not possible. Let me know!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为当您无法找到
触发器
的控制时,没有必要一直放置触发器
某些事件只需使用updatepanel而不使用触发器
这个将更新整个网格、搜索控件,它还将处理 AutoPostBack 事件,但不会忘记放置 Update
控件来查看工作正在进行中...i think its not necessary to put
Triggers
all the time when you are not able to find control forTriggers
some event just use updatepanel withouttriggers
this will update whole grids, search controls and it will also handles AutoPostBack event but dnt forget to put Update
<asp:UpdateProgress>
control to see work is in process...根据这些信息,我假设您在 MasterPage 上拥有所有页面通用的搜索控件。一种方法是从母版页公开事件并在内容页上处理它。检查此。
在您的 DDL selectedIndexChanged 事件发生后,您将引发此事件。在 contentPage 上此事件的处理程序中,您可以调用 updateContent.Update()。
我认为解决方案就在这些方面。
From the information, I assume you have your search controls on MasterPage that are common to all pages. One way would be to expose an event from your masterpage and handle it on your contentpage. Check this.
Upon your DDL selectedIndexChanged event you raise this event. Inside the handler of this event on contentPage you call updateContent.Update().
I think the solution lies somewhere along those lines.