ASP.NET弹出模态对话框


主页面 PageBase.aspx.cs 中的代码
protected   void  Page_Load( object  sender, EventArgs e)

  
if  ( ! this .IsPostBack)
  {
    
// addBtn.Attributes.Add("onclick", "javascript:ShowModalDialog('OvertimeDlog.aspx','395px','250px')");
    
// delBtn.Attributes.Add("onclick", "javascript:ShowModalDialog('OvertimeDlog.aspx','395px','250px')");
     this .addBtn.Attributes.Add( " onclick " " javascript:OpenOvertimeDlog('add',540,400) " );    //  增加 Button
     this .updateBtn.Attributes.Add( " onclick " " javascript:OpenOvertimeDlog('up',540,400) " );  //  修改 Button
  }
}

主页面 PageBase.aspx 中的代码
< head  runat ="server" >
  
< title > 无标题页 </ title >
  
< script  type  ="text/javascript"  language  = "javascript" >
   
function  OpenOvertimeDlog(frmWin,width,height) 
   {       
     
var  me; 
     
var  action;
     action 
=  frmWin;
     
//  把父页面窗口对象当作参数传递到对话框中,以便对话框操纵父页自动刷新。 
     me  =   " OvertimeDlog.aspx?action= " + action + ""
     
//  显示对话框。
     window.showModalDialog(me,null, ' dialogWidth= ' + width  + ' px;dialogHeight= ' + height + ' px;help:no;status:no '
   } 
  
</ script >
</ head >

弹出对话框页面 OpenDlog.aspx 中的代码
< head  runat ="server" >
    
< title > 无标题页 </ title >
    
<!--  防止重新打开页面形式的对话框  -->
    
< base  target ="_self"   />  
</ head >

弹出对话框页面 OpenDlog.aspx.cs 中的代码
OpenDlog.aspx.cs
{
    
protected   void  Page_Load( object  sender, EventArgs e)
    {
        
// 获得传递的 action 的值;
         string  getRequest  =  Request[ " action " ].ToString();
    }
}

对话框页面 OpenDlog.aspx.cs 关闭后,执行更新操作(在对话框的关闭事件中加入):

  Response.Write( " <script language='javascript'> " ); 
  Response.Write(
" window.close() " ); 
  Response.Write(
" </script> " ); 

 
参考:http://www.cnblogs.com/penboy/archive/2005/11/22/121773.html

你可能感兴趣的:(asp.net)