繁体   English   中英

模式对话框未关闭

[英]modal dialog not close

RegistrationPage.aspx

function btnSearchClick()
{
    if (window.showModalDialog)
    {
        window.showModalDialog(
            "Search.aspx", 
            "Search Patient", 
            "dialogWidth:800px; dialogHeight:400px"
        );
        return false;
    }
}

Search.aspx

$(document).ready(function ()
{
    $("input[id$='btnAdd']").live('click', function (e) {                   
        hidID.value = $.trim($('table td.csstablelisttdselected:first').text());
        return true;
    });
});

Seach.aspx.cs

protected void btnAdd_Click(object sender, EventArgs e)
{
    Response.Redirect("RegistrationPage.aspx?ID=" + hidID.Value, true);
    Page.ClientScript.RegisterStartupScript(
        this.GetType(), 
        "CloseScript", 
        "window.close()", 
        true
    );
}

RegistrationPage.aspx页上单击“ button搜索”弹出对话框。
Search page我在hiddenfield获取ID,并重定向到registration page
当我单击btn时,添加对话框不会关闭,它会重定向到对话框中的注册页面。

请不要给出“使用jquery对话框”或“使用其他对话框控件”之类的答案。

这是一个经过测试的示例:

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test</title>
    <script type="text/javascript">
        function btnSearchClick()
        {
            window.returnValue = undefined;
            var result = window.showModalDialog("Search.aspx", window, "dialogHeight:650px; dialogWidth:900px;");
            if (result == undefined)
                result = window.returnValue;
            if (result != null && result != "undefined")
                alert(result);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <input type="button" id="btnOpen" onclick="btnSearchClick();" />
        </div>
    </form>
</body>
</html>

Search.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Search.aspx.cs" Inherits="Search" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script>
        function CloseModal() {
            if (window.opener) {
                window.opener.returnValue = 'your return value';
            }

            window.returnValue = 'your return value';
            self.close();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        </div>
    </form>
</body>
</html>

Search.aspx.cs

using System;
using System.Web;
using System.Web.UI;

public partial class Search : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        Page.ClientScript.RegisterStartupScript(this.GetType(), "CloseScript", "closescript()", true);

    }
}

因此,您可以将Modal的值传递给Opener而不是重定向用户。

这里是另一个示例: 模态对话框ReturnValue

希望能帮上忙。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM