一方的行动Response.WriteFile后不会发生() [英] Side actions not happening after Response.WriteFile()

查看:112
本文介绍了一方的行动Response.WriteFile后不会发生()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据ASP.NET页,按钮上的下列行为应该发生的点击:

As per an ASP.NET page, on click of a button the following actions should happen:


  1. 从服务器上下载文件

  2. 执行清理像

  1. Download a file from server
  2. Perform clean up actions like


  • 隐藏一个按钮

  • 设置文本标签

  • 显示标签

  • 禁用按钮


现在下载的部分会发生通过以下code:

Now the download part happens through the following code:

Response.Clear();               
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename="+strFileName+".pdf");
Response.WriteFile(strBrowserPath); 

和剩余行动(点2)后完成。

And the remaining actions (Point 2) are done after.

不幸的是,因为Response.Clear()/ Response.WriteFile()用于剩余的服务器端动作没有发生。

Sadly, since Response.Clear()/Response.WriteFile() is used the remaining server side actions are not happening.

其它方法吗?这任何修复?

Any alternatives? Any fixes for this?

推荐答案

从使用后回到动作发送一个文件的那一刻,是在同一时间,你不能发送和网页更改(禁用按钮,改变文本等)。目前对此没有修复,因为没有一个问题,就是这样的作品。你有一管道的响应送回去。你问一个HTTP响应,你得到一个HTTP响应,你不能兼得更新页面和文件。

From the moment you use the post back action to send a file, at the same time you can not send and the page with the changes (disable button, change text, etc). There is no fixes for this because there is not a problem, is the way its works. You have one pipeline to send your response back. You ask for one http response and you get one http response, you can not have both update page and file.

现在,另类。首先是你如何去发送文件。我建议使用一个带参数的处理如 download.ashx?Dhwoload = filea.pdf 和后回到你的页面上的更新后,可以调用

Now, alternative. First of all is how you going to send the file. I suggest to use a handler with parameters like download.ashx?Dhwoload=filea.pdf and after the post back with the update on your page, you call the

window.location的=download.ashx Dhwoload = filea.pdf?

JavaScript中,一个替代的环节

javascript, with an alternative link as

< A HREF =download.ashx Dhwoload = filea.pdf?>如果文件没有自动开始下载点击此处< / A>

和使你的工作。

相关:结果
<一href=\"http://stackoverflow.com/questions/10912164/what-is-the-best-way-to-download-file-from-server\">What是从服务器下载结果文件的最佳途径
<一href=\"http://stackoverflow.com/questions/14609389/error-handling-when-downloading-file-from-asp-net-web-handler-ashx/14616216#14616216\">Error从的ASP.NET Web处理程序(ashx的)

relative:
What is the best way to download file from server
Error handling when downloading file from ASP.NET Web Handler (.ashx)

这篇关于一方的行动Response.WriteFile后不会发生()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆