简体   繁体   English

使用更新进度 C#.NET 时更新面板内的 Response.Redirect

[英]Response.Redirect inside Update Panel While Using Update Progress C#.NET

I have a web application that uses ajax with asp.net and C#.我有一个 Web 应用程序,它使用 ajax 和 asp.net 和 C#。 Now I'm trying to export a report viewer from CodeBehind (page name is original.aspx) as a PDF file when clicking on an ASP button.现在,当单击 ASP 按钮时,我正尝试从 CodeBehind(页面名称为 original.aspx)导出报告查看器作为 PDF 文件。 Everything works perfect except when I put the button within UpdatePanel.一切都很完美,除非我把按钮放在 UpdatePanel 中。 So after searching the internet, I found that Response.BinaryWrite, Response.Flush and so on don't work with UpdanePanel unless if I specify the button as a PostBackTrigger which then neglects with the purpose of using the UpdatePanel because the page have many controls and so many steps going on before reaching the export step.因此,在搜索互联网后,我发现 Response.BinaryWrite、Response.Flush 等不适用于 UpdanePanel,除非我将按钮指定为 PostBackTrigger,然后忽略使用 UpdatePanel 的目的,因为该页面有很多控件在到达导出步骤之前要进行很多步骤。

So I transferred the code for exporting to PDF to the Page Load event on another page (lets say Default.aspx) and thought to use Response.Redirect to open a new tab for the exporting page.所以我将导出为 PDF 的代码转移到另一个页面上的页面加载事件(假设 Default.aspx),并考虑使用 Response.Redirect 为导出页面打开一个新选项卡。

What really happened is that the PDF is downloaded automatically (While still being in the original Page (original.aspx)) and without redirection - Which is fine - but the UpdateProgress was activated and never stopped showing the gif picture.真正发生的是 PDF 是自动下载的(虽然仍然在原始页面(original.aspx)中)并且没有重定向 - 这很好 - 但 UpdateProgress 被激活并且从未停止显示 gif 图片。 Just keep on looping.继续循环。 When removing the UpdateProgress from the code everything runs as expected.从代码中删除 UpdateProgress 时,一切都按预期运行。 File is exported and downloaded while the button being inside the UpdatePanel (async not PostBackTrigger) and using the Response.Redirect from the CodeBehind.当按钮位于 UpdatePanel 内(异步而不是 PostBackTrigger)并使用 CodeBehind 中的 Response.Redirect 时,文件被导出和下载。

Is there any solution for disabling, killing the UpdateProgress process from code behind with only a particular click even or any other solution for this issue?是否有任何解决方案可以仅通过特定的点击或任何其他解决方案来禁用、终止代码背后的 UpdateProgress 进程?

You can set control's ID inside PostBackTrigger to postback full page instead of partial page update which causes file download issue.您可以将PostBackTrigger 中的控件 ID 设置为回整页而不是导致文件下载问题的部分页面更新

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    ...
   <Triggers>
      <asp:PostBackTrigger ControlID="DownloadButton" />
   </Triggers>
</asp:UpdatePanel>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM