user26411
user26411

Reputation: 121

onClose Event in ASP.NET

Is there an event like onLoad?

just at closing the Site (onClose)?

Upvotes: 0

Views: 6792

Answers (5)

Matthias Meid
Matthias Meid

Reputation: 12513

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

Upvotes: 1

Alexander Prokofyev
Alexander Prokofyev

Reputation: 34515

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

Upvotes: 1

mattlant
mattlant

Reputation: 15451

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.

Upvotes: 1

Rob
Rob

Reputation: 45771

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.

Upvotes: 2

Greg Dean
Greg Dean

Reputation: 30057

The closest you can get it UnLoad.

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

Upvotes: 0

Related Questions