ASP.NET-019: Response issue not available in UpdatePanel
When exporting an EXCEL file, you generally use download and save, and use Response to export the file. For example, the following example shows how to use NPOI to export an EXCEL file:
Response. clear (); Response. clearHeaders (); Response. contentType = "application/octet-stream"; Response. addHeader ("Content-Disposition", "attachent; filename =" + HttpUtility. urlDecode ("file name .xls"); Response. writeFile (temporary file path, true); Response. flush (); Response. close ();
Recently, I encountered a problem. When a control is used on the page to download the Excel function, the prompt box cannot pop up.
After analysis, it is found that it is Response and not quite suitable. The reason is that the UpdatePanel trigger method is not used for button events in the specified range.
You need to add a trigger to implement button events. The model is as follows:
<Asp: updatepanel id = "UpdatePanel1" runat = "server" updatemode = "Always"> <contenttemplate> // page content </contenttemplate> <triggers> <asp: postbacktrigger controlid = "button ID"> // or <asp: asyncpostbacktrigger controlid = "button ID"> </asp: asyncpostbacktrigger> </asp: postbacktrigger> </triggers> </asp: updatepanel>
Of course, there are two types of triggers: PostBackTrigger -- refresh the entire page and AsyncPostBackTrigger partial refresh,
In this article, if you want to support the use of Response, you must use AsyncPostBackTrigger.