After the Asp. Net Server sends an HTTP header, it cannot set the content type.
Problems found:
When Excel is exported using Npoi, the foreground page is still aspx, and the error "failed to receive a message from the server" is reported.
Solution:
"The server cannot set the content type after sending the HTTP header" error:
1. The export component uses MyXLS
2. The page uses aspx
3. The main content of the page is:
<Form id = "form1" runat = "server"> <asp: ScriptManager ID = "Scriptmanager1" runat = "server"> </asp: ScriptManager> <asp: updatePanel ID = "UpdatePanel1" runat = "server"> <ContentTemplate> <asp: button runat = "server" ID = "btnExport" Text = "export to Excel" CssClass = "btn_common" OnClick = "btnExport_Click"/> </ContentTemplate> </asp: updatePanel> </form>
If the data cannot be exported, an error in the title is returned.
The solution is to add the global refresh capability to btnExport.
Add the following code to solve the problem.
<Triggers> <% -- <asp: AsyncPostBackTrigger ControlID = ""/> -- %> <% -- refresh the UpdatePanel internal refresh value -- %> <asp: postBackTrigger ControlID = "btnExport"/> <% -- refresh all -- %> <% -- the error "the server cannot set the content type after sending the HTTP header" is reported when you click Export on April 9, July 1, 2016 -- %> </Triggers>
Summary
The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.