Solved

asp.net - session countdown timer

Posted on 2009-05-03
2
1,190 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Authentication of Web Services 3 46
Runtime Error 2 28
Run time Error 4 34
Write to file when application closes (by logoff) - VB.NET 1 20
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

919 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

12 Experts available now in Live!

Get 1:1 Help Now