子页面关闭时传值给父页面(pass value from child window to parent window, when the child window is closing)

问:

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.


答:

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 many 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 use ModalPopup control of ASP.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.
posted @   LanceZhang  阅读(1645)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示