Display SessionTimeout warning dialog appears 2 minutes before Session timeout. How to display dialog on parent page and reset again on any activities inside frame in asp.net, c#

Hi,

Problem : Timer not working on the dialog properly on the parent page default.aspx. Countdown timer changing time 129 98 78 90 120 67 89 etc like that...

problem2. clicking on any button in details frame will reset session again. Dialog will again disappear 2minutes before timeout and it should show 120 119 118 seconds left....

How to achieve that. Please change my code...

Code

MasterPage.aspx

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Masterpage.master.cs" Inherits="Masterpage" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp"%>
<%@ Register Src="~/SessionTimeout.ascx" TagPrefix="uc1" TagName="SessionTimeout" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <asp:ContentPlaceHolder id="head" runat="server">
   </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
  
       <div id="mainContent" >
        <asp:ContentPlaceHolder id="MainContent" runat="server"   >      
        </asp:ContentPlaceHolder>
    </div>
     <uc1:SessionTimeout id="SessionTimeout" runat="server"></uc1:SessionTimeout>
     
    </form>
</body>
</html>
 
SessionTimeout.ascx
 
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SessionTimeout.ascx.cs" Inherits="SessionTimeout" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp"%>
<script src="scripts/jquery-1.12.4.js" type="text/javascript"></script>
<script type="text/javascript" src="scripts/Functions.js"></script>
 
 
      <asp:ScriptManager ID="sm" runat="server" EnablePageMethods="true" />
                  <asp:LinkButton ID="lnkSession" runat="server" />
<asp:ModalPopupExtender ID="mpeTimeout" BehaviorID ="mpeSessionTimeout" runat="server" PopupControlID="pnlPopup" TargetControlID="lnkSession"
   OkControlID="btnOK"  BackgroundCssClass="modalBackground" >
</asp:ModalPopupExtender>
 
<asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopup" Style="display: none">
     <div class="header"> Session Expiring!
      </div>
 
    <div class="body">
        Your session will expire in&nbsp;<span id="seconds"></span>&nbsp;seconds.<br />
     </div>
 
    <div class="footer" align="right">
    
        <asp:Button ID="btnOK" runat="server" Text="OK" CssClass="Savebutton" CausesValidation="false" />
             
    </div>
</asp:Panel>
 

SessionTimeout.ascx.cs

using System.Configuration;
using System.Web.Configuration;
using System.Web.Services;
 
    public partial class SessionTimeout : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Session Timeout Warning Dialog
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            if (!this.IsPostBack)
 
            {
                Session["Reset"] = true;
                int timeout = GetSessionTimeout();
                Page.ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "AdminSessionTimeoutAlert(" + timeout + ");", true);
            }
        }
 
 
        [WebMethod(EnableSession = true)]
        public static int ResetSession()
        {
            HttpContext.Current.Session["Reset"] = true;
            int timeout = GetSessionTimeout();
            return timeout;
        }
 
 
        private static int GetSessionTimeout()
        {
            Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
            SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");
            return Convert.ToInt32(section.Timeout.TotalMinutes * 1000 * 60);
        }
 
 
    }
 

Web.config

<sessionState timeout="3"/>

Javascript  Functions.js

function AdminSessionTimeoutAlert(timeout) {
   var seconds = timeout / 1000;
 
     window.parent.document.getElementsByName("seconds").innerHTML = seconds;
 
    setInterval(function () {
 
        seconds--;
 
        window.parent.document.getElementById("seconds").innerHTML = seconds;
 
      }, 1000);
 
    setTimeout(function () {
       window.parent.$find("mpeSessionTimeout").show();
 
    }, timeout - 120 * 1000);
 
 
    setTimeout(function () {
 
        window.top.location.href = "SessionExpired.aspx";
 
    }, timeout);
 
};
 
function ResetSession() {
    PageMethods.ResetSession(OnSuccess);
    return false;
}
function OnSuccess(response, userContext, methodName) {
    AdminSessionTimeoutAlert(response);
}
 
 

Parent Page default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="default" MasterPageFile="~/Masterpage.Master"%>
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <div class="container">
      <iframe id="frameName1" name="frameName1" src="index.aspx" frameborder="0"></iframe>
        </div>
 
<div class="container1">
     <iframe id="frameName2" src=" details.aspx" frameborder="0"></iframe>
</div> 
</asp:Content>
 
Details.aspx
 
<%@ Page language="c#" Inherits="Details" Codebehind="DEtails.aspx.cs" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
      <script type="text/javascript" src="scripts/Functions.js"></script>
      <script src="scripts/jquery-1.12.4.js" type="text/javascript"></script>
 
 
  </HEAD>
  <body>
      
    <form id="Form1" method="post" runat="server">
              <asp:ScriptManager ID="sm" runat="server" EnablePageMethods="true" />
              <INPUT type="text" name="txtCategoryName"  size="20" maxlength="50" ID="txtCategoryName" runat="server">
 
<asp:Button text="Submit" ID="btnSubmit1" runat="server"  OnClientClick="ResetSession();"/>
     </form>
      
  </body>
</HTML>
 
Details.aspx
 
using System.Web.Services;
using System.Configuration;
using System.Web.Configuration;
 
       public partial class Details: System.Web.UI.Page
       {
              protected void Page_Load(object sender, System.EventArgs e)
              {
 
            if (!IsPostBack)
            {
                Session["Reset"] = true;
                int timeout = GetSessionTimeout();
                Page.ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "AdminSessionTimeoutAlert(" + timeout + ");", true);
            }
        }
 
        [WebMethod(EnableSession = true)]
        public static int ResetSession()
        {
            HttpContext.Current.Session["Reset"] = true;
            int timeout = GetSessionTimeout();
            return timeout;
       }
 
 
        private static int GetSessionTimeout()
        {
            Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
            SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");
            return Convert.ToInt32(section.Timeout.TotalMinutes * 1000 * 60);
        }
 

Open in new window


Hi,

Problem : Timer not working on the dialog properly on the parent page default.aspx. Countdown timer changing time 129 98 78 90 120 67 89 etc like that...

problem2. clicking on any button in details frame will reset session again. Dialog will again disappear 2minutes before timeout and it should show 120 119 118 seconds left....

How to achieve that. Please change my code...

Code

MasterPage.aspx

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Masterpage.master.cs" Inherits="Masterpage" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp"%>
<%@ Register Src="~/SessionTimeout.ascx" TagPrefix="uc1" TagName="SessionTimeout" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <asp:ContentPlaceHolder id="head" runat="server">
   </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
  
       <div id="mainContent" >
        <asp:ContentPlaceHolder id="MainContent" runat="server"   >      
        </asp:ContentPlaceHolder>
    </div>
     <uc1:SessionTimeout id="SessionTimeout" runat="server"></uc1:SessionTimeout>
     
    </form>
</body>
</html>
 
SessionTimeout.ascx
 
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SessionTimeout.ascx.cs" Inherits="SessionTimeout" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp"%>
<script src="scripts/jquery-1.12.4.js" type="text/javascript"></script>
<script type="text/javascript" src="scripts/Functions.js"></script>
 
 
      <asp:ScriptManager ID="sm" runat="server" EnablePageMethods="true" />
                  <asp:LinkButton ID="lnkSession" runat="server" />
<asp:ModalPopupExtender ID="mpeTimeout" BehaviorID ="mpeSessionTimeout" runat="server" PopupControlID="pnlPopup" TargetControlID="lnkSession"
   OkControlID="btnOK"  BackgroundCssClass="modalBackground" >
</asp:ModalPopupExtender>
 
<asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopup" Style="display: none">
     <div class="header"> Session Expiring!
      </div>
 
    <div class="body">
        Your session will expire in&nbsp;<span id="seconds"></span>&nbsp;seconds.<br />
     </div>
 
    <div class="footer" align="right">
    
        <asp:Button ID="btnOK" runat="server" Text="OK" CssClass="Savebutton" CausesValidation="false" />
             
    </div>
</asp:Panel>
 

SessionTimeout.ascx.cs

using System.Configuration;
using System.Web.Configuration;
using System.Web.Services;
 
    public partial class SessionTimeout : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Session Timeout Warning Dialog
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            if (!this.IsPostBack)
 
            {
                Session["Reset"] = true;
                int timeout = GetSessionTimeout();
                Page.ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "AdminSessionTimeoutAlert(" + timeout + ");", true);
            }
        }
 
 
        [WebMethod(EnableSession = true)]
        public static int ResetSession()
        {
            HttpContext.Current.Session["Reset"] = true;
            int timeout = GetSessionTimeout();
            return timeout;
        }
 
 
        private static int GetSessionTimeout()
        {
            Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
            SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");
            return Convert.ToInt32(section.Timeout.TotalMinutes * 1000 * 60);
        }
 
 
    }
 

Web.config

<sessionState timeout="3"/>

Javascript  Functions.js

function AdminSessionTimeoutAlert(timeout) {
   var seconds = timeout / 1000;
 
     window.parent.document.getElementsByName("seconds").innerHTML = seconds;
 
    setInterval(function () {
 
        seconds--;
 
        window.parent.document.getElementById("seconds").innerHTML = seconds;
 
      }, 1000);
 
    setTimeout(function () {
       window.parent.$find("mpeSessionTimeout").show();
 
    }, timeout - 120 * 1000);
 
 
    setTimeout(function () {
 
        window.top.location.href = "SessionExpired.aspx";
 
    }, timeout);
 
};
 
function ResetSession() {
    PageMethods.ResetSession(OnSuccess);
    return false;
}
function OnSuccess(response, userContext, methodName) {
    AdminSessionTimeoutAlert(response);
}
 
 

Parent Page default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="default" MasterPageFile="~/Masterpage.Master"%>
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <div class="container">
      <iframe id="frameName1" name="frameName1" src="index.aspx" frameborder="0"></iframe>
        </div>
 
<div class="container1">
     <iframe id="frameName2" src=" details.aspx" frameborder="0"></iframe>
</div> 
</asp:Content>
 
Details.aspx
 
<%@ Page language="c#" Inherits="Details" Codebehind="DEtails.aspx.cs" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
      <script type="text/javascript" src="scripts/Functions.js"></script>
      <script src="scripts/jquery-1.12.4.js" type="text/javascript"></script>
 
 
  </HEAD>
  <body>
      
    <form id="Form1" method="post" runat="server">
              <asp:ScriptManager ID="sm" runat="server" EnablePageMethods="true" />
              <INPUT type="text" name="txtCategoryName"  size="20" maxlength="50" ID="txtCategoryName" runat="server">
 
<asp:Button text="Submit" ID="btnSubmit1" runat="server"  OnClientClick="ResetSession();"/>
     </form>
      
  </body>
</HTML>
 
Details.aspx
 
using System.Web.Services;
using System.Configuration;
using System.Web.Configuration;
 
       public partial class Details: System.Web.UI.Page
       {
              protected void Page_Load(object sender, System.EventArgs e)
              {
 
            if (!IsPostBack)
            {
                Session["Reset"] = true;
                int timeout = GetSessionTimeout();
                Page.ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "AdminSessionTimeoutAlert(" + timeout + ");", true);
            }
        }
 
        [WebMethod(EnableSession = true)]
        public static int ResetSession()
        {
            HttpContext.Current.Session["Reset"] = true;
            int timeout = GetSessionTimeout();
            return timeout;
       }
 
 
        private static int GetSessionTimeout()
        {
            Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
            SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");
            return Convert.ToInt32(section.Timeout.TotalMinutes * 1000 * 60);
        }
 

Open in new window

Saroj13Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Answering your questions may seem easy to you, because you know your code.

For someone else to answer... they'd have to take the time to go through your code, line by line, understand it + then respond.

This is likely best handled as a Gig, so someone can get into your code + work this to complete resolution.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Marking my answer.

Poster seems to have stopped posting.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.