C#--父子页面传值、刷新(showModalDialog)
父页面:
1 var obj = new Object(); 2 obj.name="name"; 3 var rtnValue=window.showModalDialog("child.aspx",obj,"dialogWidth:500px;dialogHeight:300px;status:no;scrollbars=yes;help:no"); 4 if(rtnValue=="ok"){ 5 window.location.reload();//刷新父页面,子页面关闭 6 }
子页面关闭(两种方式):
1 ①前台(.aspx): 2 <script type="text/javascript"> 3 var obj = window.dialogArguments;//获取父页面传值(alert("您传递的参数为:" + obj.name)) 4 window.returnValue="ok";//向父页面传值 5 close();//关闭子页面 6 </script> 7 ②后台(.aspx.cs):--<head></head>之间加上<base target="_self">,close()或window.close() 8 Response.Write("<script type='text/javascript'>window.returnValue='ok';close();</script>");
子页面关闭,刷新父页面(两种方式):
1 子页面代码: 2 前台方法: 3 function refresh() { 4 window.dialogArguments.location.href = window.dialogArguments.location.href; 5 window.close(); 6 } 7 <body class="hello" onunload="refresh()"> 8 后台方法: 9 scriptString.Append("<script language = javascript>"); 10 scriptString.Append(" window.dialogArguments.location.href=window.dialogArguments.location.href;"); 11 scriptString.Append(" window.focus();"); 12 scriptString.Append(" window.close();"); 13 scriptString.Append("</" + "script>"); 14 Response.Write(scriptString.ToString());