Q: Insert Data To Database When We Try To Close The Browse I am trying to find a way to catch browser close event and call a server side code for database entry.
I have tried Javascript for window.onbeforeunload and body.onunload but unload event is fired every time the page navigates.
I need to catch only browser close event.
I am using asp.net with C# and my page have a master page.

A: Just use the code in one of these answers to call a function in your code-behind (that writes to DB)
Calling ASP.NET Code Behind function from JavaScript
Also, you can do client-side postbacks, explained on MSDN here
