In a lot of the web applications that I write, there is a need to stream a report back to the browser as a PDF.   With code something like this:


 //response to user’s web.
            Response.Expires = 0;
            Response.Buffer = true;
            Response.ClearContent();
            Response.AddHeader(“content-disposition”, “inline; filename=” + “output.pdf”);
            Response.ContentType = “application/pdf”;
            Response.BinaryWrite(outBuf);
            outStream.Close();
            Response.End();


Now that I am playing around with the Ajax Toolkit (specifically the ModalPopupExtender) in Visual Studio 2008, it has become clear that you really need to control whether you want asynch or full postback.


If your button that produces the report is in an UpdatePanel, and you are manipulating the Reponse to stream the report back, then you will probably want a normal postback.


This is accomplished by adding a Triggers element to your UpdatePanel as below:


 <asp:UpdatePanel ID=”UpdatePanel2″ runat=”server”>
<Triggers>
 <asp:PostBackTrigger ControlID=”btnApplicationOK” />
 </Triggers>


In this case the button btnApplicationOK is inside the UpdatePanel so it’s default behaviour is to perform a partial (Ajax) postback and it will not like you manipulating the Reponse, so you will get an error like the one below. The fix is to add the PostBackTrigger as mentioned.