博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
父窗弹出模态窗口子窗,取得父窗值,关闭子窗,同时刷新父窗并返回子窗值到父窗...
阅读量:7008 次
发布时间:2019-06-28

本文共 6735 字,大约阅读时间需要 22 分钟。

 

Father.aspx

 

 

<%
@ Page Language
=
"
C#
"
 AutoEventWireup
=
"
true
"
 CodeBehind
=
"
Father.aspx.cs
"
 Inherits
=
"
WebUI.Temp.Father
"
 
%>
<!
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
>我是父窗口 Father.aspx ,我用 showModalDialog 方法弹出子窗口 Child.aspx
</
title
>
    
<
meta 
http-equiv
="pragma"
 content
="no-cache"
/>
    
<
meta 
http-equiv
="Cache-Control"
 content
="no-cache"
/>
    
<
meta 
http-equiv
="Expires"
 content
="no-cache"
/>
    
<
script 
type
="text/javascript"
 language
="javascript"
>
 
<!--
        
function
 openChild() {
            
//
var k = window.showModalDialog("MainIframe.aspx", window, "dialogWidth:600px;status:no;dialogHeight:500px");
            
//
以下方法禁止缓存
            
var
 k 
=
 window.showModalDialog(
"
MainIframe.aspx?
"
 
+
 (
new
 Date()).valueOf(), window, 
"
dialogWidth:600px;status:no;dialogHeight:500px
"
)
            
if
 (k 
!=
 
null
)
                document.getElementById(
"
txbFather
"
).value 
=
 k;
        } 
//
--> 
</
script
> 
</
head
>
<
body
>
    
<
form 
id
="form1"
 runat
="server"
>
        
<
table 
border
="1"
 cellpadding
="0"
 cellspacing
="0"
 width
="600"
>
            
<
tr 
bgcolor
="#ccccff"
>
                
<
td
>
                    1、传递到父窗口的值:
<
br 
/>
                    
<
br 
/>
                    2、并能取得子窗口传递进来的值
</
td
>
                
<
td
>
                    
<
asp:TextBox  
ID
="txbFather"
 runat
="server"
 Width
="200px"
>我是父窗的初始值
</
asp:TextBox
>
                
</
td
>
            
</
tr
>
         
            
<
tr 
bgcolor
="#66cc66"
>
                
<
td 
height
="40"
>
                   
<
input 
type 
="button"
 value
="弹出子窗口"
 onclick
="openChild()"
 
/>
                   
</
td
>
                
<
td
>
               
                
</
td
>
            
</
tr
>
           
        
</
table
>
    
</
form
>
</
body
>
</
html
>

 

MainIframe.aspx

 

 

<%
@ Page Language
=
"
C#
"
 AutoEventWireup
=
"
true
"
 CodeBehind
=
"
MainIframe.aspx.cs
"
 Inherits
=
"
WebUI.Temp.MainIframe
"
 
%>
<!
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
>
</
head
>
<
body
>
    
<
form 
id
="form1"
 runat
="server"
>
    
<
iframe 
src
="Child.aspx"
 width
="100%"
 height
="100%"
  frameborder
="0"
 
></
iframe
>
    
</
form
>
</
body
>
</
html
>

 

 

Child.aspx

 

 

<%
@ Page Language
=
"
C#
"
 AutoEventWireup
=
"
true
"
 CodeBehind
=
"
Child.aspx.cs
"
 Inherits
=
"
WebUI.Temp.Child
"
 
%>
<!
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
>我是子窗口 Child.aspx ,用showModalDialog弹出的子窗口
</
title
>
    
<
base 
target
="_self"
/>
    
<
meta 
http-equiv
="pragma"
 content
="no-cache"
/>
    
<
meta 
http-equiv
="Cache-Control"
 content
="no-cache"
/>
    
<
meta 
http-equiv
="Expires"
 content
="no-cache"
/>
</
head
>
<
body
>
    
<
form 
id
="form1"
 runat
="server"
>
    
<
table 
border
="1"
 cellpadding
="0"
 cellspacing
="0"
 width
="600"
>
       
          
<
tr 
bgcolor
="#ff66cc"
>
            
<
td 
height
="50"
>
               
<
input 
type 
="button"
 value
="一、用传统的 input 关闭且返回值"
 onclick
="retrunValue()"
 
/>
             
</
td
>
              
<
td
>
               取得父窗口传递进来的值
                
<
asp:TextBox 
ID
="txbChild"
 runat
="server"
></
asp:TextBox
>
            
</
td
>
        
</
tr
>
        
<
tr 
bgcolor
="#3399ff"
>
            
<
td  
height
="50"
>
                
<
asp:Button  
ID
="Button1"
 runat
="server"
 onclick
="Button1_Click"
 Text
="二、用服务器控件 Button1 关闭且返回值"
 
/>
            
</
td
>
            
<
td
>
             可以改变上面 TextBox 的值,返回给父窗口
            
</
td
>
        
</
tr
>
        
    
</
table
>
   
    
</
form
>
</
body
>
</
html
>
<
script 
type
="text/javascript"
 language
="javascript"
>
 
<!--
    
//
var k = window.dialogArguments;
    
var
 k 
=
 window.parent.dialogArguments;
    
//
当前页中 txbChild 获得父窗口 txbFather 传递来的值 
    
if
 (k 
!=
 
null
) {
        document.getElementById(
"
txbChild
"
).value 
=
 k.document.getElementById(
"
txbFather
"
).value;
    }
    
//
将当前页 txbChild 中的值 返回到父窗口中,并关闭当前页
    
function
 retrunValue() {
        
var
 s 
=
 document.getElementById(
"
txbChild
"
).value;
        window.parent.returnValue 
=
 s;
        window.parent.close();
    } 
//
--> 
</
script
> 

 

Child.aspx.cs

 

 
protected 
void Button1_Click(
object sender, EventArgs e)
        {
            System.Text.StringBuilder cstext2 = 
new System.Text.StringBuilder();
            cstext2.Append(
string.Format(
"
<script type=text/javascript>var s ='{0}'; 
"
this.txbChild.Text.ToString()));
            cstext2.Append(
"
window.returnValue = s;window.close();</
");
            cstext2.Append(
"
script>
");
            Response.Write(
string.Format(
"
{0}
", cstext2.ToString()));
        }

 

 Parent.aspx

 

<%
@ Page Language
=
"
C#
"
 AutoEventWireup
=
"
true
"
 CodeBehind
=
"
Parent.aspx.cs
"
 Inherits
=
"
WebUI.Temp.Parent
"
 
%>
<!
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(
"
SubParent.aspx
"
, window, 
"
dialogWidth:335px;status:no;dialogHeight:300px
"
);
            
if
 (k 
==
 
1
)
//
判断是否刷新 
            {
                alert(
'
刷新
'
);
                window.location.reload();
            }
        } 
//
--> 
</
script
> 
</
head
>
<
body
>
    
<
form 
id
="form1"
 runat
="server"
>
   
<
br
>传递到父窗口的值:
<
input 
id
="txt9"
 type
="text"
 value
="3333333333333"
 
/><
br
> 
   
<
input 
type 
="button"
 value
="openChild"
 onclick
="openChild()"
 
/> 
    
</
form
>
</
body
>
</
html
>

 

SubParent.aspx

 

<%
@ Page Language
=
"
C#
"
 AutoEventWireup
=
"
true
"
 CodeBehind
=
"
SubParent.aspx.cs
"
 Inherits
=
"
WebUI.Temp.SubParent
"
 
%>
<!
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"
 
/>
<
meta 
http-equiv
="Expires"
 CONTENT
="0"
 
/> 
<
meta 
http-equiv
="Cache-Control"
 CONTENT
="no-cache"
 
/> 
<
meta 
http-equiv
="Pragma"
 CONTENT
="no-cache"
 
/> 
</
head
>
<
body
>
    
<
form 
id
="form1"
 runat
="server"
>
   
<
br
>父窗口传递来的值:
<
input 
id
="txt0"
 type
="text"
><
br
> 
<
input 
type 
="button"
 value
="关闭刷新父窗口"
 onclick
="winClose(1)"
> 
<
input 
type 
="button"
 value
="关闭不刷新父窗口"
 onclick
="winClose(0)"
>
    
<
asp:Button 
ID
="Button1"
 runat
="server"
 onclick
="Button1_Click"
 
        Text
="服务器端关闭并刷新父页"
 
/>
    
</
form
>
</
body
>
</
html
>
<
script 
type
="text/javascript"
 language
=javascript
>
 
<!--
    
var
 k 
=
 window.dialogArguments;
    
//
获得父窗口传递来的值 
    
if
 (k 
!=
 
null
) {
        document.getElementById(
"
txt0
"
).value 
=
 k.document.getElementById(
"
txt9
"
).value;
    }
    
//
关闭窗口返回是否刷新的参数. 
    
function
 winClose(isRefrash) {
        window.returnValue 
=
 isRefrash;
        window.close();
    } 
//
--> 
</
script
> 

 

SubParent.aspx.CS

 

 
protected 
void Button1_Click(
object sender, EventArgs e)
        {
            
string isFresh = 
"
1
";
            System.Text.StringBuilder cstext2 = 
new System.Text.StringBuilder();
            cstext2.Append(
string.Format(
"
<script type=text/javascript> var s ='{0}'; 
", isFresh));
            cstext2.Append(
"
window.returnValue = s;window.close();</
");
            cstext2.Append(
"
script>
");
            Response.Write(
string.Format(
"
{0}
", cstext2.ToString()));
        }

 

例子代码下载 :

转载于:https://www.cnblogs.com/tiger8000/archive/2012/03/15/2398192.html

你可能感兴趣的文章
dnspod 批量添加记录
查看>>
ZCMU训练赛-H(模拟)
查看>>
Codeforces Round #449 (Div. 2) A. Scarborough Fair【多次区间修改字符串】
查看>>
CCCC L1-039. 古风排版【图形输出/循环控制行列/模拟/细节】
查看>>
POJ 1182 食物链 【带权并查集/补集法】
查看>>
V字形
查看>>
Flask学习笔记(3)-数据库迁移
查看>>
Hbase常用操作
查看>>
一行命令学会全基因组关联分析(GWAS)的meta分析
查看>>
第二阶段冲刺——six
查看>>
模块封装代码
查看>>
《Machine Learning》(第一章)序章
查看>>
【右键禁用U盘的小技巧】
查看>>
执行sql语句后的数据处理api
查看>>
jquery $.each的用法
查看>>
Python --元组与列表的差异
查看>>
PHP TP增删改
查看>>
VMware虚拟机与主机联通及配置上网
查看>>
single-row function和muti-row function
查看>>
keepalived
查看>>