• asp.net弹出多个模态窗口


    asp.net中无限制弹出模态窗口

    特点:

    1.       可以在模态窗口上再弹出模态窗口,不限制次数

    2.       弹出窗口的支持拖放,及调整大小

    3.       弹出窗口关闭后可以动态控制是否刷新父窗口

     

     

    总共需要3个页面来做演示

    1. 页面ModalDemo.aspx

    前台代码:

    <head runat="server">
    
        <title>无标题页</title>
    
        <base target="_self"  />
    
     
    
        <script type="text/javascript">
    
     
    
    function OpenDialogWithReturn(url,width,height,formID,action)
    
    {
    
         var retValue = window.showModalDialog( url ,null,"dialogWidth:" + width + "px;dialogHeight:" + height +  "px;help:no;unadorned:yes;resizable:yes;status:no;scrollbars:yes");
    
         if (retValue !=  null && retValue != undefined && retValue == "SubmitForm")
    
         {
    
          if(action !=  null  && action != undefined && action.Length > 0)
    
           {
    
             formID.Action=action;
    
          }
    
           formID.submit();
    
             
    
         }
    
    }
    
        </script>
    
     
    
    </head>
    
    <body>
    
        <form id="form1"  runat="server">
    
        <div>
    
            <a href="#"  onclick="OpenDialogWithReturn('ModalPage1.aspx',520,410,form1,'ModalDemo.aspx');">通过页面脚本来弹出模态窗口</a><br />
    
            <br />
    
            <br /><asp:Button ID="btnDetail"  runat="server" 
    
                    onclick="btnDetail_Click" Text="通过动态注册弹出窗口" />
    
    &nbsp;<br />
    
            <div>
    
                <%=DateTime.Now %>
    
            </div>
    
        </div>
    
        </form>
    
    </body>
    View Code

    后台代码:

    protected  void btnDetail_Click(object sender,  EventArgs e)
    
            {
    
                this.ClientScript.RegisterStartupScript(this.GetType(), "", "OpenDialogWithReturn('ModalPage1.aspx',520,410,form1,'ModalDemo.aspx');", true);
    
            }

    2.第二个页面ModalPage1.aspx

    前台代码:

    <head runat="server">
    
        <title>第一个模态窗口</title>
    
        <base target="_self"  />
    
     
    
        <script type="text/javascript">
    
     
    
    function OpenDialogWithReturn(url,width,height,formID,action)
    
    {
    
         var retValue = window.showModalDialog( url ,null,"dialogWidth:" + width + "px;dialogHeight:" + height +  "px;help:no;unadorned:yes;resizable:yes;status:no;scrollbars:yes");
    
         if (retValue !=  null && retValue != undefined && retValue == "SubmitForm")
    
         {
    
          if(action !=  null  && action != undefined && action.Length > 0)
    
           {
    
             formID.Action=action;
    
          }
    
           formID.submit();
    
             
    
         }
    
    }
    
     
    
        </script>
    
     
    
    </head>
    
    <body onunload="window.returnValue='SubmitForm';">
    
        <form id="form1"  runat="server">
    
        <div>
    
            <a href="#"  onclick="OpenDialogWithReturn('ModalPage2.aspx',500,400,form1,'ModalPage1.aspx');">
    
                通过页面脚本来弹出模态窗口</a>
    
            <br />
    
            <br />
    
            <asp:Button ID="Button1"  runat="server" Text="通过动态注册脚本来弹出模态窗口" 
    
                OnClick="Button1_Click" />
    
            <br />
    
            <br />
    
            <br />
    
            <asp:Button ID="btnOK"  runat="server" OnClick="btnOK_Click" Text="确定" />
    
            <br />
    
            <div>
    
                <%=DateTime.Now %></div>
    
        </div>
    
        <asp:Button ID="Button2"  runat="server" Text="添加" />
    
        </form>
    
    </body>
    View Code

    后台代码:

    //弹出新的模态窗口
    
            protected  void Button1_Click(object sender,  EventArgs e)
    
            {
    
                this.ClientScript.RegisterStartupScript(this.GetType(), "", "OpenDialogWithReturn('ModalPage2.aspx',500,400,form1,'ModalPage1.aspx');", true);
    
     
    
            }
    
            //关闭当前窗口,并刷新父页面
    
            protected  void btnOK_Click(object sender,  EventArgs e)
    
            {
    
                this.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "window.returnValue='SubmitForm';window.close();", true);
    
     
    
            }
    View Code

    3. 第三个页面ModalPage2.aspx

    前台代码:

    <head runat="server">
    
        <title>第二个模态窗口</title>
    
        <base target="_self"  />
    
    </head>
    
    <body onunload="window.returnValue='SubmitForm';">
    
        <form id="form1"  runat="server">
    
        <div>
    
            <asp:Button ID="Button1"  runat="server" Text="ok" OnClick="Button1_Click" />
    
        </div>
    
        <div>
    
            <asp:Button ID="Button2"  runat="server" Text="添加" />
    
        </div>
    
        <br />
    
        <div>
    
            <%=DateTime.Now %></div>
    
        </form>
    
    </body>
    View Code

    后台代码:

    //关闭当前窗口,并刷新父窗口
    
            protected  void Button1_Click(object sender,  EventArgs e)
    
            {
    
                this.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "window.returnValue='SubmitForm';window.close();", true);
    
     
    
            }
    View Code

     

     

  • 相关阅读:
    全国哀悼日 灰色CSS滤镜 PENGHAO
    Jmail发信函数 PENGHAO
    XHTML 1.0 参考 PENGHAO
    今天搬家。。 PENGHAO
    JS代码Checkbox控制输入框 PENGHAO
    CSS hack:区分IE6,IE7,firefox PENGHAO
    获取表中新记录(下一条记录)的主键值的存储过程 PENGHAO
    五种提高 SQL 性能的方法 PENGHAO
    [收藏 ]针对IE网页浏览器不同版本解释的CSS或javascript PENGHAO
    小本创业者的致胜法宝! PENGHAO
  • 原文地址:https://www.cnblogs.com/J-FoX/p/3387060.html
Copyright © 2020-2023  润新知