use this code it will solve ur problem
<script type="text/javascript">
function unload()
{
var btn =document.getElementById('BtnSave');
//alert(btn);
btn.click();
// if (Flg==false)
// {
// event.returnValue = "UNSAVED DATA WILL BE LOST!!";
// }
}
</script>
<body onbeforeunload="unload()">