How To Add Session Timeout Popup in ASP.NET

If you need to alert a user that his session will time out. This is how to do it. Add the following code snippet to the OnInit method on the base page of your application.

protected override void OnInit(EventArgs e)
   {
       base.OnInit(e);
       string script = "window.setTimeout(\"alert('Your session expired!');\", " + (Session.Timeout - 1) * 60000 + ")";
       this.Page.ClientScript.RegisterStartupScript(this.GetType(), "SessionManager", "<script language=\"javascript\">" + script + "</script>");
   }

Please do not post any spam link in the comment box😊

Post a Comment (0)
Previous Post Next Post