Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force button do a full postback instead of asynchronous postback

In an ASP.NET 4.0 web application, I have a user control that is wrapped by an UpdatePanel (see the code below).

<asp:UpdatePanel ID="UpdatePanel5" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <UC:MyCustomCtrl ID="customCtrl" runat="server" />
    </ContentTemplate>
</asp:UpdatePanel>

Obviously, this works great for every ASP.NET control that causes a postback in my user control because it makes it occur asynchronously. However, there is one process that this doesn't work for!

I have an ASP.NET button (Create Report) in the user control that makes an asychronous request to the server. The server then creates an Excel spreadsheet and then places the spreadsheet in the HttpResponse to send back to the client's browser so they can open/save it. However, it blows up at this point because the request to the server is asynchronous and apparently you can't put a binary in the HttpResponse during an asynchronous request.

How do I get around this?

like image 707
Jagd Avatar asked Sep 20 '12 16:09

Jagd


People also ask

How do I stop the current asynchronous postback call?

You can also cancel the current request by using the cancel property of the Sys. CancelEventArgs class. Note: You can get the ID of the element which has initiated a new postback by 'postBackElement' property of the 'Sys. WebForms.

What is the difference between synchronous postback and asynchronous postback?

The difference between synchronous and asynchronous postback is thatAsynchronous postback renders only the required part of the page and whereas, synchronous postback renders the entire page for any postback.

What is postback trigger?

AsyncPostBackTrigger - use these triggers to specify a control within or outside of the UpdatePanel that, when clicked, should trigger a partial page postback. PostBackTrigger - use these triggers to have a control within the UpdatePanel cause a full page postback rather than a partial page postback.

What is postback trigger in UpdatePanel?

Description. <asp:AsyncPostBackTrigger> Specifies a control and event that will cause a partial page update for the UpdatePanel that contains this trigger reference.


1 Answers

Register this button as synchronous postback control in user control's Page_Load method: ScriptManager.GetCurrent(Page).RegisterPostBackControl(CreateReportButton);

like image 147
Yuriy Rozhovetskiy Avatar answered Sep 24 '22 19:09

Yuriy Rozhovetskiy