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

父窗口:

 

<% @ 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);

        }

 

 

你可能感兴趣的:(window.showModalDialog 弹出窗口,关闭子窗,刷新父窗,在 .CS 中的实现)