【问题标题】:updatepanel and updateprogress flush out PDF responseupdatepanel 和 updateprogress 清除 PDF 响应
【发布时间】:2012-09-21 00:19:30
【问题描述】:

我正在尝试使用 UpdatePanel 和 Updateprogress 在创建和刷新 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。在这件事上有什么帮助吗?

干杯。

【问题讨论】:

  • 看起来您正在将文件作为内容发送到更新面板。那是行不通的。
  • 这用 Javascript 做起来就这么简单,只需要显示和隐藏两个 div,你根本不需要使用更新面板和脚本管理器。

标签: c# asp.net updatepanel


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-14
    • 1970-01-01
    • 1970-01-01
    • 2021-11-13
    相关资源
    最近更新 更多