Click here to Skip to main content
13,408,442 members (41,209 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I found this cool session time code popup alert.
how do I invoke an event handler on session timeout
I need the data enter on a page to save minute before session time out.

I am looking at Page Method and examples, suggestions?

private void CheckSessionTimeout()
string msgSession = "Warning: Within next 3 minutes, if you do not do anything, our system will redirect to the login page. Please save changed data.";
//time to remind, 3 minutes before session end
int int_MilliSecondsTimeReminder = (this.Session.Timeout * 60000) - 3 * 60000;
//time to redirect, 5 miliseconds before session end
int int_MilliSecondsTimeOut = (this.Session.Timeout * 60000) - 5;

string str_Script = @"
var myTimeReminder, myTimeOut;
clearTimeout(myTimeOut); " +
"var sessionTimeReminder = " + int_MilliSecondsTimeReminder.ToString() + "; " +
"var sessionTimeout = " + int_MilliSecondsTimeOut.ToString() + ";" +
"function doReminder(){ alert('" + msgSession + "'); }" +
"function doRedirect(){ window.location.href='login.aspx'; }" + @"
myTimeReminder=setTimeout('doReminder()', sessionTimeReminder);
myTimeOut=setTimeout('doRedirect()', sessionTimeout); ";

ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(),
"CheckSessionOut", str_Script, true);
Posted 7-Dec-10 9:57am
Updated 7-Dec-10 11:06am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try looking at the Session_End[^] event of the Global.asax file.

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

Solution 2

There is nothing you can do in a Page event because after the page has been processed on the server it is disposed (basic ASP.NET lifecycle).

The first parameter of the setTimeout function is the function to call when the timeout happens, in this case, doReminder and doRedirect. In your case you would need to provide function that will force a submit, or invoke whatever method you use to save the data.

Finding "cool" code is fine but you must be able to understand it and determine if it fits your needs.

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 |
Web01 | 2.8.180221.1 | Last Updated 7 Dec 2010
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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