Reputation: 7306
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?
Upvotes: 6
Views: 9069
Reputation: 46
Similar to Eric's answer. I have not tried this, but it may work...
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<UC:MyCustomCtrl ID="customCtrl" runat="server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="customCtrl$btnID" />
</Triggers>
</asp:UpdatePanel>
I did something similar to this a while back for validation controls, so it seems logical that it work here too.
Use your DOM viewer (I use Chrome's element inspector) and see what your button's "NAME" is (not ID). And starting with the portion containing the overall user control's name, use the rest.
Upvotes: 0
Reputation: 9406
Make use of the triggers within the update panel to reference the custom control and an event registered on the report button within the control, e.g.
<Triggers>
<asp:PostBackTrigger ControlID="customCtrl" EventName="ReportButtonClicked" />
</Triggers>
Upvotes: 0
Reputation: 22448
Register this button as synchronous postback control in user control's Page_Load
method: ScriptManager.GetCurrent(Page).RegisterPostBackControl(CreateReportButton);
Upvotes: 13
Reputation: 2095
you can add triggers to UpdatePanels that allow full post back. here's an example
<asp:UpdatePanel ID="UpdatePanel5" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<UC:MyCustomCtrl ID="customCtrl" runat="server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnID" />
</Triggers>
</asp:UpdatePanel>
Upvotes: 0