简体   繁体   中英

Display & refresh an UpdatePanel after a postback from a different UpdatePanel?

I've got a page with two 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. What needs to happen is when the page captures an event from the ListView, the page needs to switch modes. 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:

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'. If it is being updated dynamically then it must be inside another 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? Is there a way to get asp.net to "break out" of a given UpdatePanel, but not perform a full postback?

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. 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. Or alternatively, put them both in an outer 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). From Partial-Page Rendering Overview on 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. 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.)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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