Fire event in code behind from Javascript
<p>I have the following javascript to prompt the user if he attempts to navigate away from the page. A dialog box will appear with 2 buttons 'Leave this page' and 'Stay on this page'. I would like to cause a postback which will fire a C# Event.</p>

<p>I want this postback to occur when the 'Leave this page' button is pressed.</p>

<p>How can i do this? Pardon me i am quite new to Javascript.</p>

<pre><code>&lt;script type="text/javascript" language="JavaScript"&gt;
var needToConfirm = true;

window.onbeforeunload = confirmExit;
function confirmExit() {
    if (needToConfirm)
        return "You have attempted to leave this page. This will CANCEL your current order selection.";
}
</code></pre>

<p></p>
