简体   繁体   中英

To pass id from child popup window to parent window

In the below code ihave a parent window in which there is a dropdown and link button inside data grid.When i click the linkbutton a child popup window open in which i select a employee id and store in a hidden value and pass that id to parent window and bind in dropdown.But i can't able to pass value pls any one help me to solve the issue.

Parent

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>  

CodeBehind:

ScriptManager.RegisterStartupScript(this, GetType(), "ShowPopUp", "ShowPopUp()", true) ;

Child:

function updateParent() {
    var oVal = document.getElementById("<%=hid.ClientID%>").value;
    window.opener.setValue(oVal);
    window.close();
    return false;
}
<input type="hidden" id="hid" runat="server" />

I tried this minimal code to reproduce your issue, but seems working on my end.

Here is my Parent window:

<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>

On code behind I am opening the page:

protected void btnTest_Click(object sender, EventArgs e)
{
    ScriptManager.RegisterStartupScript(this, GetType(), "ShowPopUp", "ShowPopUp()", true);
}

and on child window:

<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>

I would suggest to write a minimal code and see what causes the issue at your end. hope it helps./.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM