【发布时间】:2009-10-09 08:15:38
【问题描述】:
在我的网页中,我有一个 gridview,其中包含下载文件的链接和在单独页面中打开另一个网站的链接。当我单击链接 gridview onRowCommand 被执行并且网站在单独的窗口中打开。之后,当我刷新网页,gridview onRowCommand 再次执行,并再次在单独的窗口中打开网站,这是我不想要的。我希望当我点击链接导航到另一个网站时,只有它应该去。我的意思是在页面刷新时,gridview onRowCommand 应该不被执行。
我正在使用 Page.RegisterStartupScript 在单独的窗口中打开另一个网站。
ASP.net 2.0
谢谢
-------------------------------------------代码--- -------------
protected void grdDisplayView_onRowCommand(object sender, GridViewCommandEventArgs e) { 字符串路径 = e.CommandArgument.ToString();
if (path.Contains("http"))
{
StringBuilder sbString = new StringBuilder("<script language='javascript'>");
sbString.Append("window.open('");
sbString.Append("http://www.yahoo.com','', 'status=no,width=600,height=500,toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes,titlebar=yes,top=198,left=305');");
sbString.Append("</script>");
if ((!Page.ClientScript.IsStartupScriptRegistered("clientScriptExportView")))
{
Page.RegisterStartupScript("clientScriptExportView",sbString.ToString());
}
}
else
{
//download file which is locally
path = Server.MapPath(path);
System.IO.FileInfo file = new System.IO.FileInfo(path);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.ContentType = "Application/octet-stream";
HttpContext.Current.Response.WriteFile(file.FullName);
HttpContext.Current.Response.End();
}
}
【问题讨论】:
标签: asp.net