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.googlegroups.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.googlegroups.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..that=B4s what I thouht...it=B4s hard...put an event in each
link...
thanks!
Alberto
Hi, Mark.
according to ASP.NET 2.0 Internals :
http://msdn.microsoft.com/library/d...br />
nals.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 dis
connected 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 ha
nder for each
> anchor on the page that would fire some script to remind them, perhaps a m
essage 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.googlegroups.com...
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.googlegroups.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.googlegroups.com...
>
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.googlegroups.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
>
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment