我已經知道,Response.End()
之後的代碼不起作用。我在Response.End
之後嘗試alert
a message box
。基本上我在做什麼是我會從Excel
文件讀取數據,並檢查在Excel文件中缺少的數據。我將收集所有從Excel
文件丟失的數據,並將它們全部寫入text
文件,並會提示使用下面的代碼如何在Response.End後顯示警報
string strPath = Server.MapPath("ErrorLog") + "\\" + "ErrorLog.txt";
string FileName = "Errorlog" + ".txt";
string[] createText = { sb.ToString() };
File.WriteAllLines(strPath, createText);
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + "");
strPath.Length.ToString());
HttpContext.Current.Response.ContentType = "application/text";
HttpContext.Current.Response.WriteFile(strPath);
HttpContext.Current.Response.End();
在此之後我想顯示一個警告框,說像一些事情Invalid Data
。但我想知道我怎麼能做到這一點Response.End
//更新的代碼爲每lcarus
string strPath = Server.MapPath("ErrorLog") + "\\" + "ErrorLog.txt";
string[] createText = { sb.ToString() };
File.WriteAllLines(strPath, createText);
ClientScriptManager CSM = Page.ClientScript;
string strconfirm = "<script>if(window.confirm('Excel file has Invalid data.')){window.location.href='/Excel1/ErrorLog/ErrorLog.txt'}</script>";
CSM.RegisterClientScriptBlock(this.GetType(), "Confirm", strconfirm, false);
因此,而不是'Httpcontext'我想使用'ClientScript'右 – Dotnet
@用戶:正確。您應該能夠通過訪問頁面上的ClientScript屬性來獲取對ClientScriptManager對象的引用。 http://msdn.microsoft.com/en-us/library/system.web.ui.page.clientscript。aspx – Icarus
但是我沒有得到下載選項,我將用我的代碼更新我的問題,你可以檢查一次 – Dotnet