简体   繁体   English

从其他UpdatePanel回发后显示并刷新UpdatePanel?

[英]Display & refresh an UpdatePanel after a postback from a different UpdatePanel?

I've got a page with two UpdatePanels: 我有一个包含两个UpdatePanels的页面:

<asp:UpdatePanel id="ListUpdatePanel" runat="server" UpdateMode="conditional">
<ContentTemplate>
  <asp:ListView ... </asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>

<asp:UpdatePanel id="DetailUpdatePanel" runat="server" UpdateMode="conditional">
..
</asp:UpdatePanel>

There are postback controls in the ListView in the first panel. 第一个面板的ListView中有回发控件。 What needs to happen is when the page captures an event from the ListView, the page needs to switch modes. 需要发生的是,当页面从ListView捕获事件时,页面需要切换模式。 The code should display and then update the 2nd panel at that point. 此时应该显示代码,然后更新第二个面板。 The command event will cause a property PageMode to be set to edit, then: 命令事件将导致将属性PageMode设置为可编辑,然后:

protected override void OnPreRender(EventArgs e)
{
    ListPanel.Visible = PageMode == PageModes.List;
    EditPanel.Visible = PageMode == PageModes.Edit;
    if (PageMode == PageModes.Edit)
    {
        EditUpdatePanel.Update();
    }
    else
    {
        ListUpdatePanel.Update();
    }
    base.OnPreRender(e);
}

But it's not working, I get this error: ScriptResource.axd:868Uncaught Sys.InvalidOperationException: Could not find UpdatePanel with ID 'ctl00_ctl11_DetailUpdatePanel'. 但是它不起作用,我收到此错误: ScriptResource.axd:868Uncaught Sys.InvalidOperationException:找不到ID为'ctl00_ctl11_DetailUpdatePanel'的UpdatePanel。 If it is being updated dynamically then it must be inside another UpdatePanel. 如果要动态更新,则它必须位于另一个UpdatePanel中。

I would expect this, if my panels were set to automatic. 如果我的面板设置为自动,我会期望的。 I feel like there's something I'm not quite getting here. 我觉得有些事情我还没到达这里。 If a postback originates from inside an UpdatePanel, even though it's set to Conditional, is that control somehow tied to that UpdatePanel? 如果回发是从UpdatePanel内部发起的,即使将其设置为“有条件”,则该控件是否以某种方式与该UpdatePanel相关联? Is there a way to get asp.net to "break out" of a given UpdatePanel, but not perform a full postback? 有没有一种方法可以使asp.net“脱离”给定的UpdatePanel,但不执行完整的回发?

This came up b/c these both used to be in the same UpdatePanel, but I need to separate them because I have to implement logic to block submits in certain situations from the Details panel, which will be difficult to do if they're in the same UpdatePanel. 这是因为它们以前曾经在同一个UpdatePanel中,但是我需要将它们分开,因为我必须实现逻辑以在某些情况下阻止“详细信息”面板中的提交,如果它们位于相同的UpdatePanel。 I suspect it would work if I rendered them both all the time, and used CSS to hide the one I don't want the user to operate on for a given mode. 我怀疑如果我一直都渲染它们,并且使用CSS隐藏了我不希望用户在给定模式下进行操作的CSS,那将是可行的。 Or alternatively, put them both in an outer UpdatePanel. 或者,也可以将它们都放在外部UpdatePanel中。 But that seems like a lot of wasted bandwidth, I would hope there's a way to get this to work the way I want. 但这似乎浪费了很多带宽,我希望有一种方法可以使它按我想要的方式工作。

在第一个面板上将导致回发的按钮关联为另一个面板上的Asynctrigger

When ASP.NET receives a request from an update panel, its response only includes that panel's contents (plus view state and event validation data). 当ASP.NET收到来自更新面板的请求时,其响应仅包括该面板的内容(加上视图状态和事件验证数据)。 From Partial-Page Rendering Overview on MSDN: 从MSDN上的部分页面呈现概述中:

An asynchronous postback behaves much like a synchronous postback. 异步回发的行为非常类似于同步回发。 All the server page life-cycle events occur, and view state and form data are preserved. 发生所有服务器页面生命周期事件,并保留视图状态和表单数据。 However, in the rendering phase, only the contents of the UpdatePanel control are sent to the browser. 但是,在呈现阶段,仅UpdatePanel控件的内容被发送到浏览器。 The rest of the page remains unchanged. 页面的其余部分保持不变。

(I also recommend taking a look at the requests and responses yourself in Firebug, Fiddler, or another similar tool.) (我还建议您自己在Firebug,Fiddler或其他类似工具中查看请求和响应。)

If you're committed to using update panels (rather than jQuery or another client-side library) you're going to have to put the list and details inside a single panel. 如果您承诺使用更新面板(而不是jQuery或其他客户端库),则必须将列表和详细信息放在一个面板中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM