views:

62

answers:

2

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");
    }
}
+9  A: 

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."

sgriffinusa
Thanks! Any chance I can redirect on the click of the OK button?
kralco626
Sure, you can do as @Mario Menger suggests.
sgriffinusa
+5  A: 

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>"); 
     } 
 } 
Mario Menger
This solved this problem. Unfortunatly when I redirect to Default.aspx Default.aspx still thinks it is a timeout and redirects back to EndSession.aspx. But i'll make a new topic for this. You answered the question perfectly.
kralco626