try this code..
this only fire on referesh and browser close...not on any postback
<script type="text/javascript" language="javascript">
window.onbeforeunload = function(event)
{
var msg = 'Are you sure you want to leave?';
if (((window.event.clientX || event.clientX) < 0) || ((window.event.clientY || event.clientY)<0))
{
event=window.event;
event.returnValue = msg;
return msg;
}
if ((window.event.clientX < 0) || (window.event.clientY<0))
{
event=window.event;
event.returnValue = msg;
return msg;
}
else if (window.event.altKey == true || window.event.ctrlKey == true)
{
event=window.event;
event.returnValue = msg;
return msg;
}
else
{
}
}
</script>