473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

On page_EXIT ???

Is there an event fired when I exit from an aspx.page?

I mean, if the user clicks in any other link available on the screen, i
would like to caught thta event and pop-up , remembering to save
unsaved data...

is that possible??

Thanks

Alberto

Nov 19 '05 #1
11 2598
Are you looking for Page.OnUnload ?


Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Gordowey" <al************@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Is there an event fired when I exit from an aspx.page?

I mean, if the user clicks in any other link available on the screen, i
would like to caught thta event and pop-up , remembering to save
unsaved data...

is that possible??

Thanks

Alberto

Nov 19 '05 #2
Unfortunately, there is no such thing. Since the browser is completely
disconnected from the server immediately after it loads the last item
required for that page, there's no way to trap this. You would have to so
something like create an onclick hander for each anchor on the page that
would fire some script to remind them, perhaps a message box that reminds
them and forces them to click yes to continue and leave or no and not be
redirected.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Gordowey" <al************@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Is there an event fired when I exit from an aspx.page?

I mean, if the user clicks in any other link available on the screen, i
would like to caught thta event and pop-up , remembering to save
unsaved data...

is that possible??

Thanks

Alberto

Nov 19 '05 #3
oK thanks..that´s what I thouht...it´s hard...put an event in each
link....

thanks!

Alberto

Nov 19 '05 #4
Hi, Mark.

according to ASP.NET 2.0 Internals :
http://msdn.microsoft.com/library/de.../internals.asp
there *is* a Page.OnUnload event and it's a part
of the Page Lifecycle methods ( see Table 1).

Wouldn't that event do for what he apparently wants to do ?

Page.Unload inherits from Control :

http://msdn.microsoft.com/library/de...mberstopic.asp


Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Mark Fitzpatrick" <ma******@fitzme.com> wrote in message
news:eE**************@TK2MSFTNGP15.phx.gbl...
Unfortunately, there is no such thing. Since the browser is completely disconnected from
the server immediately after it loads the last item required for that page, there's no
way to trap this. You would have to so something like create an onclick hander for each
anchor on the page that would fire some script to remind them, perhaps a message box
that reminds them and forces them to click yes to continue and leave or no and not be
redirected.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage "Gordowey" <al************@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Is there an event fired when I exit from an aspx.page?

I mean, if the user clicks in any other link available on the screen, i
would like to caught thta event and pop-up , remembering to save
unsaved data...

is that possible??

Thanks

Alberto

Nov 19 '05 #5
Not server side (the server would do once the page is navigated away).

But you could perhaps use the onbeforeunload client side event :
http://msdn.microsoft.com/library/de...foreunload.asp

--
Patrice
"Gordowey" <al************@gmail.com> a écrit dans le message de
news:11**********************@f14g2000cwb.googlegr oups.com...
oK thanks..that´s what I thouht...it´s hard...put an event in each
link....

thanks!

Alberto
Nov 19 '05 #6
You must come from a windows forms world. While it sounds like the
right event, and it would be if we we're using a windows form, OnUnload
fires before a page is sent back to the user. It goes something like
this:

Client Request --> OnLoad --> Some more events -->OnUnload --> Response
back to client

Hooking into the OnUnload event simply allows you to do stuff as a last
step before a rendered page is sent back to the client.

As another poster mentioned, you could hook into the javascript
onbeforeunload event with something like this:

<script>
function CheckUnload()
{
if (("1" == document.forms["Form1"].IsChanged.Value))
{
if (confirm("You have unsaved changes. Click OK to save changes."))
{
document.forms["Form1"].submit();
alert("Changes saved.");

return false;
}
}
}
</script>

<body onbeforeunload="CheckUnload()">...
Best of luck,

Matt Furnari

Nov 19 '05 #7
Thanks Patrice, that link helps me a lot....

unfortunatelly this systema must be developed in webforms...not
winforms...)

Thanks ALL@@

Nov 19 '05 #8
That still wouldn't work if the user just closes the browser or types a new
web address into the address bar, selects a favorite, etc.

The only reliable way I know of is to handle the onbeforeunload event in the
browser. In this handler, you then prompt the user to cancel the operation,
and maybe make a server side call to save the data. However, the caveat is
that this event fires even if the user is just navigating to the next
logical page in your application via a link or button. So, you have to have
code that keeps track of what the user has been doing, so your handler knows
if this event is being called because the user is actually trying to close
your application, or just because the user is making a request via some
functionality in your application, and so the current page is being
unloaded.

"Mark Fitzpatrick" <ma******@fitzme.com> wrote in message
news:eE**************@TK2MSFTNGP15.phx.gbl...
Unfortunately, there is no such thing. Since the browser is completely
disconnected from the server immediately after it loads the last item
required for that page, there's no way to trap this. You would have to so
something like create an onclick hander for each anchor on the page that
would fire some script to remind them, perhaps a message box that reminds
them and forces them to click yes to continue and leave or no and not be
redirected.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Gordowey" <al************@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Is there an event fired when I exit from an aspx.page?

I mean, if the user clicks in any other link available on the screen, i
would like to caught thta event and pop-up , remembering to save
unsaved data...

is that possible??

Thanks

Alberto


Nov 19 '05 #9
re:
You must come from a windows forms world.
heh, heh... I don't.

It's just that it's *really* hard to bat for 1.000.

Baseball players win batting championships with .310 batting averages.
This league is a little tougher than that.

;-)

Thanks...

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"sp3d2orbit" <mf******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... You must come from a windows forms world. While it sounds like the
right event, and it would be if we we're using a windows form, OnUnload
fires before a page is sent back to the user. It goes something like
this:

Client Request --> OnLoad --> Some more events -->OnUnload --> Response
back to client

Hooking into the OnUnload event simply allows you to do stuff as a last
step before a rendered page is sent back to the client.

As another poster mentioned, you could hook into the javascript
onbeforeunload event with something like this:

<script>
function CheckUnload()
{
if (("1" == document.forms["Form1"].IsChanged.Value))
{
if (confirm("You have unsaved changes. Click OK to save changes."))
{
document.forms["Form1"].submit();
alert("Changes saved.");

return false;
}
}
}
</script>

<body onbeforeunload="CheckUnload()">...
Best of luck,

Matt Furnari

Nov 19 '05 #10
This is *not* Windows forms. I don't really like the ambigious webform term.
A webform runs server side to produce an HTML output that is transmited and
rendered client side. This event is a client side event that can be handle
within this HTML page to be warn when the user is about to navigate way from
its current browser window.

In a web application, "web pages" have a double personality : they have a
representation on the server (as .NET code rendering HTML code) but you can
also handle a number of things client side from the produced HTML page
(DHTML/JavaScript).

--
Patrice
"Gordowey" <al************@gmail.com> a écrit dans le message de
news:11**********************@g14g2000cwa.googlegr oups.com...
Thanks Patrice, that link helps me a lot....

unfortunatelly this systema must be developed in webforms...not
winforms...)

Thanks ALL@@

Nov 19 '05 #11
This is a problem for all web applications.

If I have a complicated application where items are saved and updated
on mulitple pages, I save all work the user has done immediately. You
cannot assume that you can save the user's work at a another point in
time. Even if you captured every link,you can't control when the user
closes the web brower (I do it accidently all the time) or hits the
back button.

Nov 19 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.