一,从子窗口传值到父窗口

父窗口html 

<script type="text/javascript" language="javascript"">
    var fHeaderPkey="";
function btnApp1_onclick(t,t1)

 { 
        var ret
=window.showModalDialog("IssueApp.aspx");//ret传回的值
        
if(ret=='undefined')
        {
            
return ;
        }
        
if(ret=='')
        {
            
return ;
        }
        
if(ret==null)
        {
            
return ;            
        }  
       
//ret=ikeli3,李科威
        var a
=ret.substring(0, ret.indexOf(","0));
        var b
=ret.substring(ret.indexOf(","01); 

        document.getElementById(t).value 
=a  //txtApp1.text=a
        document.getElementById(t1).value 
=//txtEngName.text=b        
}
</Script>

 

父窗口调用,控件一定是HTML控件

 <input ID="btnApp1"  type="Button" value="showModalDialog使用总结_sed." language="javascript" onclick="btnApp1_onclick('txtApp1','txtEngName1')"  />

     
父窗口web里面取控件的值

 Dim strApp1 As String = Request("txtApp1").Trim            '需要设置HTML 控件name="txtApp1"
 Dim strEngName1 As String = Request("txtEngName1").Trim

子窗口(跳出的窗口)html回传值 

<head runat="server">
    
<title>Untitled Page</title>
    
<base target="_self"></base>    //这个很有用,刷新后还保持原来的页面大小
    
<script type="text/javascript" language="javascript">
    
      
function DbClickEvent(d)
        {
            var ret
="";         
          
//window.alert("事件类型: DoubleClidk  作用对象: " d);
            ret
=d;            
            returnValue
=ret;     
            window.close();         
        }     
    
</script>
</head>

子窗口web里面赋值 

'通过点击GridView行取得赋值数据
Protected Sub gdvQemployee_RowDataBound(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gdvQemployee.RowDataBound
        
'首先判断是否是数据行
        If e.Row.RowType = DataControlRowType.DataRow Then
            
'当鼠标停留时更改背景色
            e.Row.Attributes.Add("onmouseover""this.style.backgroundColor='#E6F5FA'")
            
'当鼠标移开时还原背景色
            e.Row.Attributes.Add("onmouseout""this.style.backgroundColor='#FFFFFF'")
            
Dim str1 As String = e.Row.Cells(1).Text
            
Dim str2 As String = e.Row.Cells(0).Text
            
Dim str3 As String = "" & str1 & "," & str2 & ""
            e.Row.Attributes.Add(
"OnDblClick""DbClickEvent('" & str3 & "')")  '双击行触发事件
        End If
    
End Sub

二.从父窗口传值到子窗口

父窗口html,变量传值

showModalDialog使用总结_javascript_02showModalDialog使用总结_javascript_03Code
<script type="text/javascript" language=javascript>
function ShowWindow(SNO)

var ret
=window.showModalDialog("PEJudge.aspx?SNO="+SNO,"","dialogHeight: 700px; dialogWidth: 680px; dialogTop: 200px; dialogLeft: 100px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;")
}
</script>

传两个参数的。

'传两个参数
<script type="text/javascript" language="javascript">
function ShowWindow(SNO,PN)
{
var sret
=window.showModalDialog("QAJudge.aspx?SNO="+SNO+"&PN="+PN,"","dialogHeight: 560px; dialogWidth: 680px; dialogTop: 130px; dialogLeft: 100px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;scroll:no;")
 }
</script>

 

 

 父窗口html 调用

'这是GridView模板里面的调用
<ItemTemplate>
 
<input id="btnJudge" type="button" value="Judge" onclick="ShowWindow('<%#DataBinder.Eval(Container.DataItem,"SNO") %>')" />
</ItemTemplate>

子窗口web得到父窗口传过的值

Dim strIssueNo As String = Request.QueryString("SNO").ToString

三.关闭子窗口刷新父窗口

父窗口

'父窗口
<script type="text/javascript" language=javascript>
function ShowWindow(SNO)
{

var sret
=window.showModalDialog("LabJudge.aspx?SNO="+SNO,"","dialogHeight: 700px; dialogWidth: 680px; dialogTop: 100px; dialogLeft: 100px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;")

  
if(sret == "refresh"
  {
    window.location.reload();
  }

}
</script>

用上面的方式多次刷新会出现错误“新整理网页,必须重新传送资讯”用以下代替,就会解决此问题

 <script type="text/javascript" language="javascript">
function ShowWindowBJ(cmd,SNO)
 {
    eval(cmd);
    var retB
=window.showModalDialog("BatchJudge.aspx?SNO="+SNO,"","dialogHeight:500px;           dialogWidth:600px; dialogTop:60px; dialogLeft: 100px; edge: Raised; center: Yes; help:no; resizable: Yes; status: Yes;scroll:no")
   
if(retB== "refresh"
    {
      
// window.location.reload();
      
//刷新出现错误“新整理网页,必须重新传送资讯”用以下代替,就会解决此问题。
     window.location.href=window.location.href;  

    }

 }
</script>

 子窗口

<script type="text/javascript" language=javascript>
function closed()
{
  window.returnValue 
= "refresh";
  window.close();
}
</script>
</head>
<body onunload="closed()">

 

四.子窗口的刷新。打开子窗口,关掉重新打开子窗口不刷新子窗口解决,是因为url相同,url加变量值让其打开不同

与上次。 

<script type="text/javascript" language="javascript">
   
function ShowWindow(SNO,PN)
  {
    var num=Math.random();
   var sret=window.showModalDialog("PEJudge.aspx?SNO="+SNO+"&PN="+PN+"&num="+num,"","dialogHeight: 655px; dialogWidth: 759px; dialogTop: 60px; dialogLeft: 100px; edge: Raised; center: Yes; help:no; resizable: Yes; status: Yes;scroll:no")
            
   
if(sret == "refresh"
    {
        window.location.href
=window.location.href;
    }               
  }
</Script>