0

如何将 jQuery 对话框中元素的选定值传递到其父页面?

第1页.aspx

    $(document).ready(function() {
        $("#btnLookUp").click(function() {
            $("#searchActor").dialog({
                autoOpen: "false",
                resizable: "false",
                height: "250",
                width: "320"
            });
        });
    });

    $(document).ready(function() {
        $("#btnSearch").click(function() {
            $("#actorsList").load("LookUp/ActorsList.aspx", { lname: $("#txtSearchCriteria").val() });
        });
        return false;
    });

    function SelectGrid(objValue, itemValue , popUpDialog) {
        $(objValue).val(itemValue);
        $(popUpDialog).dialog("close");                       
    }

ActorsList.aspx 代码隐藏

private void LoadActors(string param)
    {
        DataTable dt = new DataTable();
        //Execute stored proc

        Response.Write("<table>");
        foreach (DataRow dr in dt.Rows)
        {
            Response.Write("<tr>");
            Response.Write("<td>" + "<label onclick='SelectGrid(#txtActorId,0,#searchActor'>Select</label>" + "</td>");
            Response.Write("<td>" + dr[2].ToString() + "</td>");
            Response.Write("<td>" + dr[3].ToString() + "</td>");
            Response.Write("<td>" + dr[4].ToString() + "</td>");
            Response.Write("</tr>");
        }
        Response.Write("</table>");
    }

`

另外,请帮我解决这一行,我在如何分配值时遇到了麻烦,所以我将其设置为 0。 Response.Write("<td>" + "<label onclick='SelectGrid(#txtActorId,0,#searchActor'>Select</label>" + "</td>");

4

2 回答 2

0

In the parent window you need to create an event listener(please note that this is now an absolutely cross-browser solution, here's support list)

function listener(event) {
  if( event.origin != 'http://your-domain.com') { //means data comes from another domain
    return;
  }
  document.getElementById("msg").innerHTML = "Recieved: " + event.data;
}

if (window.addEventListener){
  window.addEventListener("message", listener, false);
} else {
  window.attachEvent("onmessage", listener);
}

in the frame form where you wont to send data:

var win = window.parent;
win.postMessage("Hello", "http://your-domain.com");

if you need the description for the fully cross-browser solution feel free to ask in comment, the general approach is threw "hashbangs"

于 2013-04-25T07:53:35.773 回答
0

上面贴出的代码的场景是这样的,我有一个查找按钮,当用户点击那个按钮时,它会加载 searchactor 对话框(一个 jquery 对话框)。在这个对话框中,用户可以搜索演员列表,它加载一个 aspx 页面 (ActorsList.aspx)。用户将在列表中选择一个演员(即在查找对话框中),它将显示在演员 ID (txtActorId) 上。这就是为什么我有一个名为 SelectGrid 的函数将数据从查找对话框发送到 Page1.aspx。我找到了一个页面http://www.ezzylearning.com/tutorial.aspx?tid=6942119它做同样的事情,但是,在我的例子中,我从一个单独的页面加载 jquery 对话框中的数据。

于 2013-04-25T08:54:42.660 回答