Click here to Skip to main content
12,394,788 members (75,152 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 7-Dec-10 8:57am
postonoh1.9K
Updated 7-Dec-10 10:06am
v5
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

Cheers
Uwe
  Permalink  
Rate this: bad
 
good
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.
  Permalink  
v2

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 | Mobile
Web01 | 2.8.160721.1 | Last Updated 7 Dec 2010
Copyright © CodeProject, 1999-2016
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