C# 将id从子弹出窗口传递到父窗口
在下面的代码中,我有一个父窗口,其中数据网格内有一个下拉和链接按钮。当我单击链接按钮时,会打开一个子弹出窗口,在其中我选择一个员工id并存储在一个隐藏值中,然后将该id传递给父窗口并绑定到下拉列表中。但我无法传递值,请任何人帮助我解决这个问题 母公司C# 将id从子弹出窗口传递到父窗口,c#,javascript,jquery,asp.net,C#,Javascript,Jquery,Asp.net,在下面的代码中,我有一个父窗口,其中数据网格内有一个下拉和链接按钮。当我单击链接按钮时,会打开一个子弹出窗口,在其中我选择一个员工id并存储在一个隐藏值中,然后将该id传递给父窗口并绑定到下拉列表中。但我无法传递值,请任何人帮助我解决这个问题 母公司 function ShowPopUp() { var sFeatures = "dialogHeight: 400px;"; var myWindow = window.open("/Trans/Quote.
function ShowPopUp() {
var sFeatures = "dialogHeight: 400px;";
var myWindow = window.open("/Trans/Quote.aspx", "Quote",
"width=900, height=200", sFeatures);
window.document.getElementById("<%= btnHiddenForUpdate.ClientID%>").click();
}
function setValue(myVal) {
alert(myVal);
document.getElementById("<%=ddlEMP.ClientID%>").value = myVal;
}
<asp:DropDownList ID="ddlEMP" runat="server"
CssClass="cbSupplierName" EnableViewState="True" Width="25%" >
</asp:DropDownList>
<ItemTemplate>
<asp:LinkButton ID="lnkQuote" runat="server" CommandName="Quote" Text="Quote" />
</ItemTemplate>
我尝试了这个最小的代码来重现您的问题,但似乎在我这边起作用 这是我的父窗口:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function ShowPopUp() {
var sFeatures = "dialogHeight: 400px;";
var myWindow = window.open("Default2.aspx", "Quote",
"width=900, height=200", sFeatures);
}
function setValue(myVal) {
alert(myVal);
document.getElementById("<%=ddlEMP.ClientID%>").value = myVal;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlEMP" runat="server"
CssClass="cbSupplierName" EnableViewState="True" Width="25%">
<asp:ListItem Text="testing1" Value="testing1" />
<asp:ListItem Text="testing" Value="testing" />
</asp:DropDownList>
<asp:Button Text="text" runat="server" ID="btnTest" OnClick="btnTest_Click" />
</div>
</form>
</body>
</html>
在子窗口上:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function updateParent() {
debugger;
document.getElementById("<%=hid.ClientID%>").value = "testing";
oVal = document.getElementById("<%=hid.ClientID%>").value;
window.opener.setValue(oVal);
window.close();
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button Text="text" runat="server" ID="btnTest" OnClientClick="return updateParent()" />
<input type="hidden" id="hid" runat="server" />
</div>
</form>
</body>
</html>
我建议您编写一个最少的代码,看看是什么导致了您的问题。
希望有帮助。/。弹出窗口是否显示,updateParent是否工作,它是否命中了setValue?@Kyojimaru是的,它保留了id但没有传递值通过不传递值,您的意思是alertmyVal结果为空,还是没有添加到DropDownList中在UpdatePreent中放置一个警报,并查看您在oVal变量中得到的值。您还能够看到您在setValuemyVal函数中放置的警报吗?如果是,那么它是否为空?@Kyojimaru setValue函数未启动
protected void btnTest_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, GetType(), "ShowPopUp", "ShowPopUp()", true);
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function updateParent() {
debugger;
document.getElementById("<%=hid.ClientID%>").value = "testing";
oVal = document.getElementById("<%=hid.ClientID%>").value;
window.opener.setValue(oVal);
window.close();
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button Text="text" runat="server" ID="btnTest" OnClientClick="return updateParent()" />
<input type="hidden" id="hid" runat="server" />
</div>
</form>
</body>
</html>