admin管理员组

文章数量:1323330

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

本文标签: aspnetjavascript alert not firingStack Overflow