updatepanel和updateprogress刷新PDF响应



Am正在尝试使用UpdatePanel&在创建并刷新PDF时,更新进度以显示等待消息。参见代码

<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
  <ProgressTemplate>
    Loading.......
  </ProgressTemplate>
</asp:UpdateProgress> 
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
  <Triggers>
    <asp:AsyncPostBackTrigger ControlID="BT_Create" />
  </Triggers>
  <ContentTemplate>   
    <asp:LinkButton ID="BT_Create" runat="server" OnClick="BT_Create_Click">Download</asp:LinkButton>
  </ContentTemplate>
</asp:UpdatePanel>
protected void BT_Create_Click(object sender, EventArgs e)
{
    byte[] downloadBytes = pdfConverter.GetPdfBytesFromHtmlString(htmlCodeToConvert, baseUrl);
    System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
    response.Clear();
    response.AddHeader("Content-Type", "binary/octet-stream");
    response.AddHeader("Content-Disposition", "attachment; filename="test.pdf; size=" + downloadBytes.Length.ToString());
    response.Flush();
    response.BinaryWrite(downloadBytes);
    response.Flush();
    response.End();
}

问题是我可以让等待消息出现,但没有返回PDF:S。在这件事上有什么帮助吗?

干杯。

这是因为您正在尝试Response.BinaryWrite到更新面板,但无法完成。您只能将html发送回更新面板。

请查看此链接,该链接解释了问题并提供了简单的解决方案。

最新更新