Click here to Skip to main content
13,801,184 members
Rate this:
Please Sign up or sign in to vote.
Hi, I would like to have a countdown timer (example: 60min) for my websites so that the timer can countdown as I navigated from one webpage to another webpage until I click on the Logout button or the timer will auto logout the user once the 60min countdown is reached. I was not able to get the required timer codes from Google search because either the timer cannot be started or activate upon successfully login or  the timer will always restarted/reset by itself on the redirected webpage which mean it is not able to continue the countdown process from one webpage to another webpage. Thanks.

What I have tried:

Google Search, Code project, and Stackoverflow, and W3Schools.
Posted 10-Apr-17 23:19pm
Updated 11-Apr-17 9:43am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can store a value within the current Request such that it will be accessible within the Response.

In your case, on successful login, set countdown timer(example: 60) in response and add it to header of response as below.

Add below code after authenticating user and before redirecting user to next page.
// Add a custom value to the Request (in this case a random number)
Response.AddHeader("YourCountdownTimerValue", Convert.ToString(60));
// Redirect to your other page
This will add Count down timer value to your Response within Dashboard.aspx by simply checking the appropriate header value as below:
// Ensure the header exists
if(Request.Headers["YourCountdownTimerValue"] != null)
    // It does exist, so parse it's value (as an integer if you need it)
    int passedValue = Convert.ToInt32(Reqeuest.Headers["YourCountdownTimerValue"]);
    // Otherwise no value was present within the header, handle accordingly

On Dashboard.aspx page, you can assign value of
to any javascript variable and display it as count down timer and decrement it's value as per your choice.

Now, again, if user navigates to other page, you can write this value as header of request and get value of this variable in new page as above.

Simple.!! Hope it makes sense to you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.181215.1 | Last Updated 11 Apr 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100