下载文件/另存为 .Net 不起作用
我有一个基于 jquery lightbox 的屏幕,我想在单击链接按钮时下载文件,但允许我保存的弹出框没有出现...我下面得到的简单测试代码如果放置它就可以工作在表单加载中,但如果我将其放在超链接的服务器端单击事件中,则不会。有什么想法吗?
Response.ContentType = "text/plain";
Response.AppendHeader("Content-Disposition", "attachment; filename=event.txt");
Response.Write("test");
Response.Flush();
Response.End();
通过firebug查看,响应头如下所示,但实际响应只是页面重新加载时的html。
Response Headers
Cache-Control private
Transfer-Encoding chunked
Content-Type text/plain; charset=utf-8
Server Microsoft-IIS/7.5
X-AspNet-Version 2.0.50727
Content-Disposition attachment; filename=event.txt
X-Powered-By ASP.NET
Date Fri, 03 Jun 2011 03:21:25 GMT
I've got a jquery lightbox based screen which I want to download a file when a link button is clicked, but the popup box allowing me to save is not appearing... The simple test code I've got below works if put it in the form load but not if I put it in the server side click event of the Hyperlink. Any ideas why?
Response.ContentType = "text/plain";
Response.AppendHeader("Content-Disposition", "attachment; filename=event.txt");
Response.Write("test");
Response.Flush();
Response.End();
Looking through firebug, the Response Headers are as below, but the actual response is just the html for the page as it reloads.
Response Headers
Cache-Control private
Transfer-Encoding chunked
Content-Type text/plain; charset=utf-8
Server Microsoft-IIS/7.5
X-AspNet-Version 2.0.50727
Content-Disposition attachment; filename=event.txt
X-Powered-By ASP.NET
Date Fri, 03 Jun 2011 03:21:25 GMT
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我尝试过的一个实验:
标记:
代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DownloadFile(对象发送者,EventArgs eventArgs)
{
Response.ContentType = "文本/纯文本";
唯一
不同的是我使用 OnServerClick 而不是 OnClick。
这对我在 Firefox 3.6 和 IE9 上有效。
Here's an experiment I tried:
Markup:
Code behind:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DownloadFile(object sender, EventArgs eventArgs)
{
Response.ContentType = "text/plain";
}
The only thing different is I used OnServerClick instead of OnClick.
This works for me on Firefox 3.6 and IE9.