发送要下载的文件后显示消息

在发送要下载的文件后,我想在我的aspx页面上更新一些内容。 (之前显示的一些错误消息。)。 我相信这是不可能的,但你会给我一个解决方案吗?

以下是发送文件以供下载的代码:

Response.ContentType = "Application/zip"; Response.AddHeader("Content-Disposition", "attachment; filename=" + e.CommandArgument); Response.BinaryWrite(fileStream.ToArray()); Response.Flush(); Response.Close(); Response.End(); 

编辑澄清:我也相信没有合理的解决方案。 但是,可能有一个我不知道的Javascript技巧。

这是我能想象到的最简单的方式。

  Click here to Download  

在我的代码背后我有

 protected void Page_Load(object sender, EventArgs e) { if(Request["download"]=="1") { try { Response.ContentType = "html/text"; Response.AddHeader("Content-Disposition", "attachment; filename=file.txt"); Response.Write("content of the file"); Response.Flush(); Response.Close(); Response.End(); } catch (Exception) { //An error occurred Response.Redirect("Error.aspx"); } } } 

由于它只是一个链接,如果找不到该文件,浏览器将显示“未找到”。 如果服务器端出现错误,则重定向到错误页面。 如果你想要一个更详细的解决方案,我建议使用XMLHttpRequest。