Page Close Event In ASP.NET??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

IS There An EventHandler or Script To Catch When The Page Is Closing(similar to the Closing event in WInforms)

Thanks
 
Hello =?Utf-8?B?VmlubnkgVmlubg==?=,

Depending on what you're trying to do... If you're trying to catch the browser window closing, then you'll need to do that via client side javascript (<body onUnload="someMethod()"/>

If you want to trap when the page gets unloaded on the server side (ie: after it's sent to the browser, your event is Page.Unload.
 
If the user closes out the browser without something posting that data back
to the server, then you're out of luck.
However, if you keep track of what the user's doing, and place that data
somewhere in their session, or in a databade, then you could do something
when the user's session ends. (a result of them closing out the browser).

If you're working with IE only, then I guess you could create a client-side
javascript function that created an xmlhttp (ActiveX) object and posted the
form's information to the server as an XML document (where this function
executes on the page's onUnload Event). But that also means the function
would run every time the page posts back too. To get around this, you could
check the event's X,Y coordinates to see if it happened inside of the window
(is it happened at a negative Y coordinate, then the user clicked "x")

These are just sone random musings...Hope they help


Vinny Vinn said:
I apologize for not be clear as to what i am trying to do.

When the page is x out (not Redirected) i would like to save (to a
database) any data that the user entered.
 
David
Thanks for your suggestions
How would i get the x,y coordinates from the unload event?
 
Hello David,

I've recently done something quite similar to this. However, I set up a web service that would accept the data to write it into the database.

The client browser had <body onUnload="saveData();">, with a reference to a javascript file that defined the saveData method.

This method was responsible for generating the SOAP envelope and using the XMLHTTP object to submit this to the web service.

A fairly clean implementation, if I do say so myself, given that we were targeting only IE5+.
 
Back
Top