check for unsaved form before moving to another form
<p>I am using Asp.net Javascript and C#</p>

<p>I have a content page, and left  side has links in the master page.The content page has data entry form. If user leaves the page without submitting the form and click the cancel button. user should be prompt to save the changes made. I know i can use window.onbeforeleave and can show the confirm message.</p>

<p>Below is the issue.</p>

<ol>
<li><p>The control moves to executing the code behind page of the clicked link.Reason is on clicking the link, a javascript function is being called. this function has below code.</p>

<p>window.location.href = 'anotherpage.aspx'</p></li>
<li><p>The confirm message appears later.</p></li>
</ol>

<p>My query is, Is there any way to show the confirm message first.</p>

<p>I cannot write the confirmation message code in java script function as there are so many other links in left menu and same situation can arrise to prompt the user for confirmation message and logic is different in all pages to check the unsaved forms.</p>

<p>Suggestions?</p>
