本文介绍了重定向到“谢谢”并立即提供下载文件的保存对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASP.NET2.0。我已经创建了一个下载表单与一些输入字段和一个下载按钮。当点击下载按钮时,我想将用户重定向到谢谢您下载...页面,并立即提供他/她的文件保存。



我有以下代码显示savefile对话框:

  public partial class ThankYouPage:System.Web.UI.Page 
{
protected void Page_Load(object sender,EventArgs e)
{
Response.Clear();
Response.AddHeader(Content-Disposition,
attachment; filename = \downloadedFile.zip\);
Response.ContentType =application / x-zip-compressed;
Response.BinaryWrite(this.downloadedFileByteArray);
Response.Flush();
Response.End();
}
}

显然,此代码不允许显示任何谢谢消息。有没有一个AfterRender事件或类似的页面,我可以移动这个下载代码,并给页面的机会,向用户呈现谢谢消息?毕竟,我真的很感谢他们,所以我想表达。

解决方案

你可以参考一个下载页面您的感谢页面使用IFrame

 < iframe src =DownloadFile.aspxstyle =display:none; /> 

在这种情况下,DownloadFile.aspx将有您的示例中的代码。


I am using ASP.NET2.0. I have created a download form with some input fields and a download button. When the download button is clicked, I want to redirect the user to a "Thank you for downloading..." page and immediately offer him/her the file to save.

I have this following code to show the savefile dialog:

public partial class ThankYouPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();
        Response.AddHeader("Content-Disposition",
                          "attachment; filename=\"downloadedFile.zip\"");
        Response.ContentType = "application/x-zip-compressed";
        Response.BinaryWrite(this.downloadedFileByteArray);
        Response.Flush();
        Response.End();
    }
}

Obviously, this code does not allow to display any "Thank you" message. Is there an "AfterRender" event or something similar of the Page where, I could move this download code and give a chance for the page to render the "thank you" message to the user? After all, I am truely thankful to them, so I do want to express that.

解决方案

You could reference a download page from your thank you page using an IFrame

<iframe src="DownloadFile.aspx" style="display:none;" />

In this case, DownloadFile.aspx would have the code behind from your example.

这篇关于重定向到“谢谢”并立即提供下载文件的保存对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 02:03