My code is set up to detect user navigation or closing of the page. It triggers a post back on close, but not when the user navigates away. Strangely, if I include an alert message, it is triggered at all times.
Also, there is a timer on the page that is disabled after its first tick. However, there always seems to be a post back trigger when navigating away with the event target being the timer. I suspect this issue may have been caused by clearing the 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("You are navigating away"); // This message is triggered consistently.
__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")
{
// Perform task here
}
}
}
Thanks in advance.