Javascript warning does not fire

I have a new page with the following: Response.Redirect works, but I do not 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");
    }
}
+3
source share
2 answers

Response.Redirect redirects the browser and your javascript is not executing.

Try redirecting in 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>"); 
     } 
 } 
+7
source

Feedback Response.Redirect never returns a code to the user. It immediately redirects the user to the next page. From MSDN to Response.Redirect: "Any response body content such as HTML display text or Response.Write text on the page specified by the source URL is ignored."

+9

Source: https://habr.com/ru/post/1758415/


All Articles