Utilizing Asp.net JavaScript and C# for my project.
In the content page, there is a data entry form on the right side with links on the left in the master page. If a user leaves the page without submitting the form and clicks the cancel button, they should be prompted to save any changes made. I am aware that I can use window.onbeforeleave to display a confirmation message.
The current issue at hand is as follows:
Upon clicking a link, the control moves to execute the code behind page of the clicked link before displaying the confirm message. This behavior is caused by a JavaScript function being called on click, containing the following code:
window.location.href = 'anotherpage.aspx'
The confirmation message only appears after the code execution.
I am looking for a way to display the confirmation message first.
Embedding the confirmation message directly into the JavaScript function is not feasible as multiple links exist on the left menu, each requiring different logic to check for unsaved forms.
Any suggestions or solutions would be greatly appreciated.