Q:
I have a modal dialog window that pops up to allow the user to enter line item Info (via a datalist ). when the user closes this dialog via an OK button I created, I am returning the total value of the line items to the parent form to be displayed. how can I pass this value if the user clicks the window close ('x') button instead of my OK? I tried adding <body onUnload = 'retvalue () '>, but this caused an issue with my DataGrid (whenever the 'edit' button was clicked, the dialog closed ). can I either disable the close button and force the user to click 'OK', or capture the click event on the close button to return the value.
A:
I have read the thread carefully, and based on my understanding, what you need is that, open a modal dialog window, for some user input, then, when user click the "OK" button, or click "X" to close, in your main page, you want get some message, which from user input, is right?
If so, as far as I can see, for your information, handle the onUnload Event is not seemly in your solution, whereas, There are too other ways can achieve that:
A.As far as I can see, "disable the X button" seems impossibility, but you can use a pop Div instead of the pop window, just refer to the following link:
Http://forums.asp.net/p/1264542/2372747.aspx#2372747
B.You can useModalpopup controlASP. NET Ajax Control Toolkit, easy and handle
The modalpopup extender allows a page to display content to the user in a "Modal" manner which prevents the user from interacting with the rest of the page.
Http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ModalPopup/ModalPopup.aspx
C.Some open-source demo, can meet your needs, please refer to the following link:
Http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/
D.Handle the "X" button click event, but it seems not work in Firefox
< Script Language = " Javascript " >
<! --
Function Window. onbeforeunload ()
{
If (Event. clientx > Document. Body. clientwidth && Event. clienty < 0 | Event. altkey)
{
Window. event. returnvalue="Are you sure to exit?";
}
}
// -->
< / SCRIPT>
Otherwise, I suggest you to add a confirm dialog when your onbeforeunload event, to remind user click the "OK" button.
If I 've misunderstood your problem, feel free to reply.
Thanks.