Click here to Skip to main content
15,878,970 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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(myTimeReminder);
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
Updated 7-Dec-10 10:06am
v5

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

Cheers
Uwe
 
Share this answer
 
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900