javascript警报没有解雇

kra*_*626 3 javascript asp.net alert

我有一个新页面,其中包含以下内容:Response.Redirect有效,但我手头没有得到弹出窗口...

有任何想法吗???

   protected void Page_Load(object sender, EventArgs e)
{
    if (Request.QueryString["timeout"] != null && Request.QueryString["timeout"].ToString().Equals("yes"))
    {
        Response.Write("<script>alert('Your Session has Timedout due to Inactivity');</script>");
        Response.Redirect("Default.aspx");
    }
}
Run Code Online (Sandbox Code Playgroud)

sgr*_*usa 9

Response.Redirect调用永远不会将代码返回给用户.它会立即将用户重定向到下一页.来自Response.Redirect上的MSDN:"忽略原始URL指示的页面中显示的HTML文本或Response.Write文本等任何响应正文内容."


Mar*_*ger 7

Response.Redirect浏览器重定向和你的JavaScript没有得到执行.

尝试使用JavaScript重定向:

 protected void Page_Load(object sender, EventArgs e) 
 { 
     if (Request.QueryString["timeout"] != null && Request.QueryString["timeout"].ToString().Equals("yes")) 
     { 
          Response.Write("<script>" +
               "alert('Your Session has Timedout due to Inactivity');" +
               "location.href='Default.aspx';" + 
               "</script>"); 
     } 
 } 
Run Code Online (Sandbox Code Playgroud)