Gajulapalle.rajesh
Gajulapalle.rajesh

Reputation: 59

PageClose Event in asp.net

when user close the web site that time i need to call some function here, what was the event for user close the page or browser in asp.net(C#).

Upvotes: 1

Views: 89

Answers (2)

Peter Rasmussen
Peter Rasmussen

Reputation: 16922

You cannot do this with asp.net. The server does not know when the user closes the window. However you can use javascript, and attach an beforeunload event to the body tag.

window.onbeforeunload = function (e) {
   //javascript code here
}

Here is a good SO thread on how this can be achieved.

Upvotes: 2

walther
walther

Reputation: 13600

There is no event in asp.net that could catch the event of user closing the window, because that happens on client-side. Your C# code runs on the server without any knowledge of the client's software.

There are some mechanisms using javascript and sending some data using ajax, but no one should rely on that.

Upvotes: 0

Related Questions