I have a data grid and 2 buttons on a page, when a user cancels the window, i want to displat a popup asking the whethere they are sure they want to cancel.
i currently have
<SCRIPT> function SaveChanges() { event.returnValue = "You will loose all unsaved changes, please update details before closing the window."; } </SCRIPT>
Problem is, this message comes up even when clicking the buttons on the page, which is wrong, i want it to happen only when the user closes/cancels the window. Please help
[ December 13, 2006: Message edited by: kanumuri koti ] [ December 13, 2006: Message edited by: Bear Bibeault ]
You need to add a flag to all of the events that cause a post back. (aka set a JavaScript variable onclick) In the SaveChanges you have to check to see if that flag/bit was flipped or not. Than you know if it should be shown.
You will never get the same feel as a client application.
You can also use the "closed" property on the window.opener object to determine whether the window that opened the window in question is still open (are you still with me?). For example:
<script type="text/javascript"> if (window.opener.closed) alert("You killed my boss!") else alert("My boss is still alive!") </script>