In this article I will explain with an example, how to display Session Time out (Expire) Warning message using jQuery in ASP.Net with C# and VB.Net.
The concept is to display a Session Timeout (Expire) Counter using jQuery Dialog Modal Popup to inform the User that Session will expire soon.
The Session Timeout has been set to one minute for this article.
<sessionState timeout = "1"/>
HTML Markup
The HTML Markup consists of two HTML SPAN elements for displaying the Timeout Counter and an HTML DIV which will be displayed using jQuery Dialog Modal Popup for displaying the Warning message.
<h3>Session Idle:&nbsp;<span id="secondsIdle"></span>&nbsp;seconds.</h3>
<div id="dialog">
    Your Session will expire in&nbsp;<span id="seconds"></span>&nbsp;seconds.<br />
    Do you want to reset?
You will need to import the following namespaces.
using System.Configuration;
using System.Web.Configuration;
Imports System.Configuration
Imports System.Web.Configuration
Determining the Session Timeout from the Web.Config file
The following code gets the value of Session Timeout from the Web.Config file and then passes it to the SessionAlert JavaScript function which is called using the ClientScript.RegisterStartupScript function.
protected void Page_Load(object sender, EventArgs e)
    if (!this.IsPostBack)
        Session["Reset"] = true;
        Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
        SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");
        int timeout = (int)section.Timeout.TotalMinutes * 1000 * 60;
        ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "SessionExpireAlert(" + timeout + ");", true);
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        Session("Reset") = True
        Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration("~/Web.Config")
        Dim section As SessionStateSection = DirectCast(config.GetSection("system.web/sessionState"), SessionStateSection)
        Dim timeout As Integer = CInt(section.Timeout.TotalMinutes) * 1000 * 60
        ClientScript.RegisterStartupScript(Me.GetType(), "SessionAlert", "SessionExpireAlert(" & timeout & ");", True)
    End If
End Sub
Client Side Scripting
Following is the function which accepts the Session Timeout value from server side and then displays a Session Timeout counter. When there’s 20 seconds left for Session Timeout the jQuery Dialog Modal Popup with the Warning message is displayed.
If the user clicks OK button inside the jQuery Dialog Modal Popup, the page is redirected and the Session is refreshed and if the user clicks Close then the jQuery Dialog Modal Popup closes.
As soon as the Session expires, user is redirected to the Session Expired page.
<script type="text/javascript" src=""></script>
<script src="" type="text/javascript"></script>
<link href=""
    rel="stylesheet" type="text/css" />
<script type="text/javascript">
    $(function () {
            autoOpen: false,
            modal: true,
            title: "Session Expiring",
            buttons: {
                Ok: function () {
                Close: function () {
    function SessionExpireAlert(timeout) {
        var seconds = timeout / 1000;
        setInterval(function () {
        }, 1000);
        setTimeout(function () {
            //Show Popup before 20 seconds of timeout.
        }, timeout - 20 * 1000);
        setTimeout(function () {
            window.location = "Expired.aspx";
        }, timeout);
    function ResetSession() {
        //Redirect to refresh Session.
        window.location = window.location.href;
The jQuery Modal Popup displaying the Warning message
Display Session Time out Warning message using jQuery in ASP.Net
The Session Expired Page
Display Session Time out Warning message using jQuery in ASP.Net