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>

后台代码:

    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>

后台代码:

//弹出新的模态窗口

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

 

        }

 

2.      第三个页面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>

后台代码:

        //关闭当前窗口,并刷新父窗口

        protected void Button1_Click(object sender, EventArgs e)

        {

            this.ClientScript.RegisterClientScriptBlock(this.GetType(), "","window.returnValue='SubmitForm';window.close();"true);

 

        }

posted @ 2013-10-25 10:38  skynetfy  阅读(387)  评论(0编辑  收藏  举报