Solved

asp.net - session countdown timer

Posted on 2009-05-03
2
1,183 Views
Last Modified: 2012-08-14
We have an asp.net application written in vb.net 2008 against framework 3.5

We use master pages. We want to have a countdown on the master page which resets to 20 minutes each postback and starts counting down so the user knows when their session will expire. We have a label in a Table cell which is the label to be updated. I can change this from a server label to an html label if this will make it easier.

I tried a few examples but couldnt get the thing to go. Can anyone show me one which will work in the environment i mentioned above?
0
Comment
Question by:tfsln
2 Comments
 
LVL 8

Accepted Solution

by:
ppittle earned 500 total points
ID: 24292618
I'd recommend adding a countdown timer JavaScript function/ GUI element to your masterpage code behind.  Each time you build out the JavaScript, you can set (and re-set) the countdown timer.
There are numerous examples of javascript timers all over the web, for example:
http://www.hashemian.com/tools/javascript-countdown.htm

Using that example, I mocked up an example of how to dynamically add it to the page each time. :
<%@ page %>
<html>
<head runat="server">
<asp:Label ID="CountDownTimerJavaScriptLabel" runat="server" />
</head>
<body></body>
</html>

<%-- Code Behind --%>
protected void Page_Load(object sender, EventArgs e)
{
CountDownTimerJavaScriptLabel.Text =
"<script language="JavaScript">" +
"TargetDate = \"" + DateTime.Now.AddMinutes(20).ToString() + "\";" +
"BackColor = \"palegreen\";" +
"ForeColor = \"navy\";" +
"CountActive = true;" +
"CountStepper = -1;" +
"LeadingZero = true;" +
"DisplayFormat = \"%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.\"; " +
"FinishMessage = "It is finally here!"; " +
"</script> " +
"<script language=\"JavaScript\" src=\"http://scripts.hashemian.com/js/countdown.js\"></script> ";

}
0
 
LVL 3

Expert Comment

by:GregTSmith
ID: 24292733
I had a little different impression of what you were looking for and have attached it.
CountdownTimer.htm.txt
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now