views:

86

answers:

2

I'm developing a website in VB.NET/ASP.NET 2.0.

I want to invoke an event (Server Side) once a user leaves my site by putting a different URL in the address bar, is it possible? If so, how?

A: 

You can use the onbeforeunload JavaScript event to trigger when a user is about to navigate away from your site.

George Stocker
+1  A: 

Invoke the onbeforeunload event, like such :

window.onbeforeunload = function () {
    //Your logic
};
Andreas Grech
"Your Logic" would have to do a callback to your server to fire the appropriate event on the server.
Greg Ogle
how can i do it server side?
If you want to do processing on the server, you would have to use ajax...by sending a request to the server in that onbeforeunload function, because you can't directly invoke a method on the server from the client's page
Andreas Grech
can you please elaborate some more...
Research a bit about Ajax, which allows you to talk to the server without a complete postback (ie without refreshing the page). That is the only way you can contact the server without a refresh
Andreas Grech