ASP.NET中的页面刷新

Gud*_*ddu 2 c# asp.net

保存对话框将文件保存到本地计算机.但在那之后,我的页面就站在那里,对我的剩余工作没有任何作用.我使用下面的代码打开一个保存对话框

protected void lnkbtnDownload_Click(object sender, EventArgs e)
{
  string fileName = startupPath + "bin\\Inbox.mdb";
  System.IO.FileInfo targetFile = new System.IO.FileInfo(fileName);

  if (targetFile.Exists)
  {
      Response.Clear();
      Response.AddHeader("Content-Disposition", "attachment; filename=" + targetFile.Name);
      Response.AddHeader("Content-Length", targetFile.Length.ToString());
      Response.ContentType = "application/octet-stream";
      Response.WriteFile(targetFile.FullName);                        
      Response.End();
  }
}
Run Code Online (Sandbox Code Playgroud)

HTML代码是:

<asp:Button id="lnkbtnDownload" runat="server" CausesValidation="false" 
  Text="Download" CssClass="buttonstyle"  OnClick="lnkbtnDownload_Click"></asp:Button>
Run Code Online (Sandbox Code Playgroud)

但是在将文件保存到本地计算机并且保存对话框关闭后,我的页面根本没有响应.保存对话框关闭后,我可以知道如何回页.

And*_*ery 9

因为您正在调用Response.End,所以这会暂停页面的响应.


Haa*_*ked 5

将此代码放在HttpHandler中,然后从原始页面链接到该处理程序,传入处理程序所需的任何信息.