You can use the onunload or the onbeforeunload events to execute codes when the browser is about to closed.
You may also use Page Methods, see below
http://aspalliance.com/1294_CodeSnip_Handle_Browser_Close_Event_on_the_ServerSide.all
The code below will simulates the closed button of the browser when the user invoked the button and display an alert message..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function doSomething()
{
alert('Widnow is about to close');
}
</script>
</head>
<body onunload="doSomething();">
<form id="form1" runat="server">
</form>
</body>