Click here to Skip to main content
11,494,851 members (52,562 online)
Rate this: bad
good
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 9:57am
Edited 7-Dec-10 11: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
0 Dnyaneshwar@Pune 692
1 Sergey Alexandrovich Kryukov 350
2 CHill60 318
3 Sascha Lefèvre 280
4 Nakul Chaudhari 236
0 Sergey Alexandrovich Kryukov 10,297
1 OriginalGriff 8,821
2 Sascha Lefèvre 3,864
3 Maciej Los 3,412
4 Richard Deeming 2,500


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 7 Dec 2010
Copyright © CodeProject, 1999-2015
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