This article shows how to display the remaining minutes as a counter for a session to timeout on the Webpage that will change after every minute and a message will be displayed when the session timeout will be equal to 0 (zero).
One thing to keep in mind is that the code provided will neither timeout the session or is it responsible for any session related activity. It will just show the timeout counter on the screen depending on the session timeout set within the application. If any additional things are required, additional code has to be written.
It might be possible that in some applications, a developer wants to display the time left for the session to be over or timeout. That will enable the user to save the entered information or it can be used for any other purpose depending on the requirement.
var sessionTimeout = "<%= Session.Timeout %>";
document.getElementById("<%= lblSessionTime.ClientID %>").innerText =
sessionTimeout = sessionTimeout - 1;
if (sessionTimeout >= 0)
alert("Your current Session is over.");
protected void Page_Load(object sender, EventArgs e)
Figure 1: When the application starts.
Figure 2: After 1 minute.
Figure 3: When session counter comes to 0, the message box will be displayed.
- 26th March, 2008: Initial post