ASP.NET:如何传递窗口.返回C#代码的值

ASP.NET: How to pass window.ReturnValue to C# code?

本文关键字:代码 返回 窗口 NET 何传递 ASP      更新时间:2023-09-26

我使用showModalDialog函数打开弹出窗口,即ASP.NET页面。在我从下拉列表中选择一些选项后,我填充窗口。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();
}

我使用Firefox。

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

使用jQuery:

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

或javascript:

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

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