On exit page event

P

Peter Larsen [CPH]

Hi,

How do i track when i move away from a page - aka "window.onbeforeunload",
but on server side.

If you think of a sample where you have some textbox's and you want to get
the contents, before moving away from the page, but you don't want to use
post-back on each textbox. How is that done ??

At the moment, i'm trying an idea where i use the following script in on
window.onbeforeunload. This gives me a postback where i have the opportunity
to read from the page before moving away (or if a button is pushed and
similar stuff).

function doOnBeforeUnload()
{
__doPostBack('nothing', '');
}

But i am not sure what the consequences are, using this method. Do i break
something or is it a possible solution ??
There is one problem though - if using session states, data could be
overwritten with data from older pages. But that could be solved by writing
a timestamp to the page.

So, is postback a solution or are there other ways to do this ??

Best Regards
Peter
 
P

Peter Larsen [CPH]

Hi Mark and thanks for your comments.

The alternative is a popup message on onbeforeunload, but that leaves me
with other problems (like getting too many popups) !

Calling __doPostBack from onbeforeunload looks very similar to a normal
button click (postback) where the control hasn't no OnClick method assigned
to it. The only difference is that the event also will be fired when you
close the tab or browse to a new page.

To me it sounds like a win-win - except that i should be more careful about
not getting newer data destroyed by older data.
Postback is a possible solution, but bear in mind that the onbeforeunload
/ beforeunload will fire *every time* the page closes...

What do you mean about "every time" ??

BR
Peter
 
P

Peter Larsen [CPH]

Hi Mark,

Do you know of a better way to accomplish this (save data before exit) ??

/Peter
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top