I have the following code to detect user navigation or close. The post back is triggered on close but not when navigated away. If i place a alert message it is triggered at all times.
Oh and there is a timer on the page which is actually disabled after first tick. but there is always a post back triggers when navigating away with eventtarget timer. I think this may be because i have cleared cache for the previous page.
<script src="Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(window).bind("beforeunload", function () {
alert("u r navigating away"); // this message gets triggered at all times.
__doPostBack('callPostBack');
});
</script>
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string eventTarget = this.Request["__EVENTTARGET"];
string eventArgument = this.Request["__EVENTARGUMENT"];
if (eventTarget != String.Empty && eventTarget == "callPostBack")
{
//do task
}
}
}
Thanks in advance.