On page_EXIT ???

  • Thread starter Thread starter Gordowey
  • Start date Start date
G

Gordowey

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
 
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
 
oK thanks..that´s what I thouht...it´s hard...put an event in each
link....

thanks!

Alberto
 
Hi, Mark.

according to ASP.NET 2.0 Internals :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/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/d.../html/frlrfsystemwebuicontrolmemberstopic.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/
======================================
 
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
 
Thanks Patrice, that link helps me a lot....

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

Thanks ALL@@
 
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.
 
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 said:
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
 
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).
 
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.
 

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

Back
Top