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?
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.
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.
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.
Description. <asp:AsyncPostBackTrigger> Specifies a control and event that will cause a partial page update for the UpdatePanel that contains this trigger reference.
Register this button as synchronous postback control in user control's Page_Load
method: ScriptManager.GetCurrent(Page).RegisterPostBackControl(CreateReportButton);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With