Friday, March 16, 2012

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

AlbertoAre you looking for Page.OnUnload ?

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Espaol : http://asp.net.do/foros/
======================================
"Gordowey" <albertoiriarte@.gmail.com> wrote in message
news:1130431340.421969.246570@.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
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" <albertoiriarte@.gmail.com> wrote in message
news:1130431340.421969.246570@.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
oK thanks..thats what I thouht...its hard...put an event in each
link...

thanks!

Alberto
Hi, Mark.

according to ASP.NET 2.0 Internals :
http://msdn.microsoft.com/library/d...l/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...emberstopic.asp

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Espaol : http://asp.net.do/foros/
======================================
"Mark Fitzpatrick" <markfitz@.fitzme.com> wrote in message
news:eEaKtax2FHA.2268@.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" <albertoiriarte@.gmail.com> wrote in message
> news:1130431340.421969.246570@.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
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/d...eforeunload.asp

--
Patrice

"Gordowey" <albertoiriarte@.gmail.com> a crit dans le message de
news:1130432315.940034.103810@.f14g2000cwb.googlegr oups.com...
oK thanks..thats what I thouht...its hard...put an event in each
link...

thanks!

Alberto
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.

"Mark Fitzpatrick" <markfitz@.fitzme.com> wrote in message
news:eEaKtax2FHA.2268@.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" <albertoiriarte@.gmail.com> wrote in message
> news:1130431340.421969.246570@.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
>>
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 Espaol : http://asp.net.do/foros/
======================================
"sp3d2orbit" <mfurnari@.gmail.com> wrote in message
news:1130434360.479309.211030@.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
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" <albertoiriarte@.gmail.com> a crit dans le message de
news:1130435385.042534.258600@.g14g2000cwa.googlegr oups.com...
> Thanks Patrice, that link helps me a lot...
> unfortunatelly this systema must be developed in webforms...not
> winforms...)
> Thanks ALL@.@.
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.

0 comments:

Post a Comment