最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - javascript alert not firing - Stack Overflow

programmeradmin0浏览0评论

I have a new page with the following: The Response.Redirect works, but I don't get a popup before hand...

Any ideas???

   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");
    }
}

I have a new page with the following: The Response.Redirect works, but I don't get a popup before hand...

Any ideas???

   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");
    }
}
Share asked Aug 6, 2010 at 14:57 kralco626kralco626 8,65441 gold badges115 silver badges171 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

The Response.Redirect call never returns the code to the user. It immediately redirects the user to the next page. From the MSDN on Response.Redirect: "Any response body content such as displayed HTML text or Response.Write text in the page indicated by the original URL is ignored."

The Response.Redirect redirects the browser and your JavaScript does not get executed.

Try redirecting in JavaScript instead:

 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>"); 
     } 
 } 
发布评论

评论列表(0)

  1. 暂无评论