0

我使用 showModalDialog 函数打开弹出窗口,这是 ASP.NET 页面。在下拉列表中选择一些选项后,我填充 window.ReturnValue 并按 OK 按钮。模态弹出窗口关闭,但我不知道如何将返回值传递给后面的 C# 代码以继续进行。

这是代码:

打开弹出窗口:

function ClientItemClicked(sender, eventArgs)
{
    if (eventArgs.get_item().get_value() == "excel")
    {
        var retVal = window.showModalDialog("ExportToExcelChoice.aspx", null, "dialogWidth: 400; dialogHeight: 200; center: yes; resizable: no;");
    }
}

关闭弹出窗口:

function ReturnValue() {
    var choice = document.getElementById("DropDownList1").value;
    if ((window.opener != null) && (!window.opener.closed)) {
        window.ReturnValue = choice;
        var result = window.ReturnValue;
    }
    window.close();
}

我使用火狐。

4

1 回答 1

1

创建服务器端隐藏输入并为其分配返回值。

使用 jQuery:

$("#<%=serverhidden.ClientID%>").val(retVal)

或 javascript:

document.getElementById("<%=serverhidden.ClientID%>").value = retVal

现在在回发时,您可以从服务器端的隐藏输入中访问该值。

于 2013-02-15T06:51:38.487 回答