【问题标题】:modal dialog not close模态对话框未关闭
【发布时间】:2013-02-11 17:33:22
【问题描述】:

RegistrationPage.aspx

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

搜索.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 add 时,对话框没有关闭,它重定向到对话框内的注册页面。

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

【问题讨论】:

  • 你有没有先关闭再重定向?
  • 是的,我试过了,但同样的事情发生了“对话框没有关闭,它重定向到对话框内的注册页面。”
  • 你的 html 对话框是什么?分区?框架?
  • 在 html 中......
  • 你说“它在模态窗口中打开”——对我来说听起来像是 iFrame,可能是问题的根源——你应该知道你的软件在做什么。

标签: c# javascript asp.net web-applications modal-dialog


【解决方案1】:

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

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,而不是重定向您的用户。

这里是另一个例子:Modal Dialog ReturnValue

希望能帮上忙。

【讨论】:

  • 我已经更改了答案并发布了一个完整的示例。看看吧。
猜你喜欢
  • 2012-02-16
  • 1970-01-01
  • 2020-06-20
  • 2011-08-01
  • 2016-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多