window.showModalDialog 弹出窗口,关闭子窗,刷新父窗,在 .CS 中的实现

本文详细介绍了如何在Web页面中利用弹窗功能实现父窗口与子窗口之间的数据传递与交互,包括JavaScript函数的调用、参数传递及窗口关闭时的数据反馈。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

父窗口:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PopWindow.aspx.cs" Inherits="WebUI.PopWindow" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
   
        <script type="text/javascript" language="javascript">
<!--
            
function openChild() {
                
var k = window.showModalDialog("StreetTreeViewModule.aspx", window, "dialogWidth:335px;status:no;dialogHeight:300px");
                
if (k == 1)//判断是否刷新 
                {
                    alert(
'刷新');
                    window.location.reload();
                }
            }
//--> 
        </script>

</head>
<body>
    <form id="form1" runat="server">

      传递到父窗口的值:<input id="txt9" type="text" value="2500" name="txt9"/>

    <input name="cat" onclick="openChild()" type="button" value="弹出窗口"/>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </form>
</body>
</html>

 

弹出的子窗口:StreetTreeViewModule.aspx

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StreetTreeViewModule.aspx.cs" Inherits="WebUI.StreetTreeViewModule" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <base target="_self"/>
<script type="text/javascript" language="javascript">
<!--
    
var k = window.dialogArguments;
    
//获得父窗口传递来的值 
    
    
//关闭窗口返回是否刷新的参数. 
    function winClose(isRefrash) {
        window.returnValue 
= isRefrash;
        window.close();
    }
//--> 
        </script>

</head>
<body>
    <form id="form1" runat="server">

     <table width="80%">
     <tr>
        <td align="left" height="100">

<input id="Button2" onclick="winClose(1)" type="button" value="关闭刷新父窗口" name="CloseRefresh"/>
<input id="Button3" onclick="winClose(0)" type="button" value="关闭不刷新父窗口" name="CloseNoFresh"/>
 <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
         </td>
     </tr>
    </table>
    </form>
</body>
</html>

 

StreetTreeViewModule.aspx.CS  中

 

 protected void Button1_Click(object sender, EventArgs e)
        {
            this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), Guid.NewGuid().ToString(), "winClose(1);"true);

        }

 

 

转载于:https://www.cnblogs.com/tiger8000/archive/2011/10/21/2220016.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值