• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1226
  • Last Modified:

asp.net - session countdown timer

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
tfsln
Asked:
tfsln
1 Solution
 
ppittleCommented:
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
 
GregTSmithCommented:
I had a little different impression of what you were looking for and have attached it.
CountdownTimer.htm.txt
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now