1:注意:Response.Redirect("a.html")是不能跳出框架、IFRAME的。
可以使用
Response.Write("<script Language=\"Javascript\">top.location=\"login.aspx\";</script>");
asp.net中Page.ClientScript.RegisterStartupScript用法小結
http://blog.csdn.net/qiujialongjjj/article/details/6680252
//ASP.NET后台頁面跳轉 Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>if(confirm('保存成功!是否繼續添加?')){location.href='ProductonAdd.aspx'}else{location.href='ProductonList.aspx'}</script>"); //后台彈出確定框 ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('請正確輸入!');</script>"); //ASP.NET后台頁面跳轉 Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('數據添加成功!');{location.href='ProductonList.aspx'}</script>"); 或 Page.ClientScript.RegisterStartupScript(typeof(string), "", "<script>window.location.href='AdminMain.aspx';</script>"); //后台彈出文本框 ScriptManager.RegisterStartupScript(Page, typeof(string), "popUp", "window.open('rptView.aspx','打印預覽','toolbar=no,location=no,scrollbars=yes,top=200px,left=200px,width=904px,height=650px')", true);
ASP.NET的Page類的RegisterStartupScript函數解析
http://blog.163.com/budong_weimin_zh/blog/static/129198524201062024654838/
ScriptManager.RegisterStartupScript 方法
http://www.cnblogs.com/weicleer/archive/2012/11/28/2792421.html
使用 RegisterStartupScript 方法,可為與部分頁面呈現兼容且不具有 Microsoft AJAX Library 依賴項的頁面注冊啟動腳本塊。 僅當正在注冊該塊的控件位於要更新的 UpdatePanel 控件內時,才將通過使用此方法注冊的啟動腳本塊發送到頁面。 若要在每次發生異步回發時都注冊啟動腳本塊,請使用該方法的 RegisterStartupScript(Page, Type, String, String, Boolean) 重載。
如果要注冊與部分頁面更新無關的啟動腳本,並且只想在初始頁面呈現期間注冊一次該腳本,請使用 ClientScriptManager 類的RegisterStartupScript 方法。 可以從頁面的 ClientScript 屬性獲取對 ClientScriptManager 對象的引用。
RegisterStartupScript 方法所呈現的腳本塊會在頁面完成加載之時、但頁面的客戶端 onload 事件引發之前執行。 啟動腳本塊位於呈現的 ASP.NET 頁面底部的 </form> 標記之前。
不能保證使用 RegisterStartupScript 注冊的啟動腳本塊按照其注冊順序輸出。 如果啟動腳本塊的順序很重要,請使用 StringBuilder 對象將腳本塊集中到一個字符串中,然后將它們作為單個啟動腳本進行注冊。
protected override void OnInit(EventArgs e) { if (Request.Cookies["userinfo"] != null && Request.Cookies["userinfo"]["UserCode"] != null) { //to do other thing } else { //Response.Write("<script>parent.location='../SysManage/login.aspx'</script>"); Response.Write("<script Language=\"Javascript\">window.location=\"../SysManage/login.aspx\";</script>"); Response.End(); //Response.Redirect("../SysManage/login.aspx");//注:當網頁回退時,上面兩種方式並不能夠返回 return; } base.OnInit(e); }
注意:
當網頁回退時:
如果有iframe時,采用redirect方法是可以返回的,但是只是將iframe中的網頁返回,此時顯示是有問題的。
當采用write方法時,需要執行Response.End(); 否則子類會繼續執行下去,響應請求。當調用end方法時,會立即停止該頁的執行