see this example:-
<script type="text/javascript">
function unload()
{
if (document.getElementById('HdnisSave').value =='0')
{
event.returnValue = "UNSAVED DATA WILL BE LOST!!";
}
}
</script>
<body onbeforeunload="unload()" >
<asp:HiddenField ID="HdnisSave" runat="server" Value="0" />
when your browser close than this js will inform you that your browser is closed and your data will be unsaved and give you some option like leave this or stay this page.
i hope it will help you.
when you save data than set hidden field value =1.