Question on Control.Unload event

G

Gauthier Segay

Hello,

I've an application where all my pages implement a PAGE_CODE string
property, this property is stored in HttpContext.Current.Items.

In some page, I must persist data in session while the user perform
operation on this page (postback navigation based). I also need to
clean up the session data when the user leave the page (by a anyway).

My question is about the Unload event, is it safe to use the unload
event and check if the PAGE_CODE is out of scope to remove session
variables that are used in the unloaded page?

I ask this because after some tests, it happen that unload is trigged
on the next navigation within the same session and I can't find any
clear description on when this event will be trigged on the server side.

Either way, what is your strategy to remove unneeded variables in
session? Does anyone allready use the Unload event?

Thanks for your insight.

Gauthier
 
G

Guest

the Unload for triggered as the last event during the page execution.
Page_Unload is the counterpart to Page_Init .. That also implies, for each
post back the unload events for control and page are being executed.

I doubt if I understand the requirement correctly.. if you are looking for a
way to find if the user is done with a page and is navigating to another page
, there is no event supported for that.. Unloading of a page doesn't happen
when user close the browser or navigate to a different page.

Unload event is good for cleaning up resources used during the page
execution.
 
G

Gauthier Segay

Hello,

thanks for your answer,

I'm not trying to do anything when the user close his browser window,
I'm trying to determinate when the unload event is really trigged and
if it's reliable to use it the way I described.

I'm unsure that the Unload event is trigged at the end of the request,
because in development environment, when I put breakpoint in this event
handler, it's not getting called after the request was sent to the
client browser, but it's effectively trigged on the subsequent request.

I suppose I should investigate another way to maintain/clean session
variables but the fact that the unload event seemed to be trigged on
next postback would have helped because only the page I came from
really knows which session variables have to be removed.

Do you use reliably the Unload event and did it fires just after the
request was sent or on the subsequent postback?

Regards,

Gauthier
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top