XuGang

记录一个程序员的成长

 

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

posted on   钢钢  阅读(5977)  评论(2编辑  收藏  举报

编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架

导航

统计

点击右上角即可分享
微信分享提示