Mindan Mindan - 1 year ago 113
Javascript Question

ASP .NET Timeout implementation with Display Timeout error message

I want to implement a timeout function on my ASP .net web application. So that the user will be redirected to Timeout message after 60 min.
I used the following in the webconfig

<sessionState timeout="60"></sessionState>


I could not find any usfull example online for this task.
I wonder if there is anyway to implement this on client side with jQuery or Javascript?

Answer Source

Fixed the problem by implementing a jQuery function that execute in clinet side, and redirect the user to time out page.

     $(document).ready(function () {
        var timeInSeconds = 30
        var timeoutTimer = timeInSeconds * 1000;
        var timeoutToRefresh = window.setTimeout(timeoutfunction, timeoutTimer)


        var isPostBack = ("true" === "<%= Page.IsPostBack ? "true" : "false" %>");

        if (!isPostBack) {
            $('#cost').hide();
            $('#imgCost').attr("src", "../../Design/Images/iconPlus.png");
        } else {
            $('#imgCost').attr("src", "../../Design/Images/minus_icon.png");
        }
    });

    var timeoutfunction = function () {
        window.location.replace('/CustomErrorPage.aspx')
    };
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download