tags:

views:

1005

answers:

6

Is there an event like onLoad....just at closing the Site (onClose)?

A: 

The closest you can get it UnLoad.

http://msdn.microsoft.com/en-us/library/ms178472.aspx

Greg Dean
+1  A: 

Not in the sense that I suspect you're thinking. All your code in ASP.net runs on the server which doesn't inherently "know" when the site is closed by the user. To achieve what you're after, you'd need to use Javascript to handle the window.onunload / window.onbeforeunload events and trigger some form of request to the server.

Take a look at http://developer.mozilla.org/en/DOM/window.onunload for more information on the window.onunload event.

Update: If you're using/able to use ASP.net AJAX, there's some quite tidy wrappers there that provide you with a similar set of events/beahviours to the server-side page lifecycle. There's a pretty decent tutorial from Stephen Walther on his blog.

Rob
+1  A: 

"Closing the side" means that the user closes the browser window on his client, right?

In JavaScript you have the OnUnload-event. If you need an event on the server, then you might be able (I never tried) to push the event to the server by hand using a custom client script. But you do not have it out-of-the box, because it's a client event.

Hope this helps.

Cheers Matthias

Mudu
+1  A: 

I would suggest using asp.net ajax for this. See this link of page lfecycle for this, which shows the application.unload event (triggers when the page is being closed, navigated away from).

This fits well with asp.net for obvious reasons, better than using onunload event directly, unless of course you do everything without asp.net ajax. The only thing it cant do is notify you in the case the browser crashes.

mattlant
A: 

Thank u for your quick response I solved my problem

Please share with the rest of us by posting a solution, and/or voting up or down.
Greg Dean
+1  A: 

You could use with limitations Session_End method in ASP.NET application file (Global.asax).

Alexander Prokofyev