请教大侠们,如何关闭一个下载产生的空白页面?(之前有类似的问题,但是都没有解决的办法)
在gridview中点击下载按钮链接到一个下载页面,再在这个页面中弹出下载对话框,现在问题是,点击下载按钮时,同时弹出一个空白页面和下载对话框,下载完之后,空白页面也不关闭,请问有没有好的解决方案.
下载页面的代码如下:
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream ";
Response.AppendHeader( "Content-Disposition ", "attachment;filename= " + HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(fileName)));
Response.AppendHeader( "Content-Length ", DownloadFileDfd.Length.ToString());
Response.TransmitFile(fileName);
Response.Write( " <script language= 'javascript '> window.close(); </script> ");//这个脚本不起作用......
Response.Flush();
Response.End();
------解决方案--------------------public class Download : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 得到文件路径
string path = Server.MapPath(Request.Params[ "File "]);
System.IO.FileInfo file = new System.IO.FileInfo(path);
// 清空当前请求缓冲器
Response.Clear();
// 添加文件头细详信息到下载保存对话框中
Response.AddHeader( "Content-Disposition ", "attachment; filename= " + file.Name);
// add the header that specifies the file size, so that the browser
// can show the download progress
Response.AddHeader( "Content-Length ", file.Length.ToString());
// specify that the response is a stream that cannot be read by the
// client and must be downloaded
Response.ContentType = "application/octet-stream ";
// send the file stream to the client
Response.WriteFile(file.FullName);
// stop the execution of this page
Response.End();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
书下扒来的!这样下载不会有白框!
------解决方案--------------------楼上正解,按照楼上 慕白兄 的方法吧
------解决方案--------------------新页面没关系.
<a href taget这里不用taget或target=_set