相关文章推荐
热心肠的茶叶  ·  執行緒模型 - WPF .NET ...·  11 月前    · 
直爽的马克杯  ·  kivy-ios: install ...·  1 年前    · 
成熟的柳树  ·  使用git ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I use the following method to downlaod attachment:

public void OpenDocument(byte[] AttContent, string fileName, string inExtension)
    Response.Clear();
    Response.ClearHeaders();
    Response.ClearContent();
    Response.ContentType = "application/pdf";
    Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + inExtension);
    Response.AddHeader("Content-Length", AttContent.Length.ToString());
    Response.BinaryWrite(AttContent);

But since the content is inside an update panel I get the following error:

"Sys.WebForms.PageRequestManagerParserErrorException: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed."

If you run fiddler to see the response, I'm guessing you'll see your download. The problem is the partial page rendering. When the client side gets it thinks it should be getting a page update and instead gets a binary file. There's a couple of solutions:

Option #1, disable partial page rendering entirely for the page (must be done in page_init):

protected void Page_Init(object sender, EventArgs e)
  ScriptManager mgr = ScriptManager.GetCurrent(this);
  mgr.EnablePartialRendering = false;

Option #2 force a postback with the control initiating the download:

ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(BtnExport);

Option #3 create a postback trigger

<asp:updatepanel id="UpdatePanel1" runat="server">
    <triggers>
        <asp:postbacktrigger ControlID="BtnExport"/>
    </triggers>
</asp:updatepanel> 
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.