Maideen 0 Newbie Poster

Hi Sir
I have a problem in passing value from Popop to main page
I am using Master page and aspx page

From main page, i can open popup windows and populate data in gridview. I am selecting date and capture the valeu in TextBox. When I click the button nothing happened. It shows popup windows only.. Pls advise me

Thank you.
Maideen
It is my Code - Popup

<body>
    <form id="form1" runat="server">
        <asp:Label ID="Label1" runat="server" Text="Select Item Name"></asp:Label>
        <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
        <asp:Button ID="btnSearch" runat="server" Text="Search" />
        <asp:TextBox ID="txtItemName" runat="server"></asp:TextBox>
        <asp:Button ID="btnSelectItem" runat="server" Text="select Item" OnClientClick="SetName();" />

    <div>
        <script type="text/javascript">
            function SetName() {
                if (window.opener != null && !window.opener.closed) {
                    var txtItemID = window.opener.document.getElementById("txtItemID");
                    txtItemID.value = document.getElementById("txtItemName").value;
                }
                window.close();
            }


        </script>


    <br />
     <asp:GridView ID="GridView1" runat="server" CssClass="gridview" AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" 
        BorderWidth="1px" CellPadding="3" GridLines="Horizontal" PageSize="15" Font-Names="Calibri" Font-Size="Small">
        <AlternatingRowStyle BackColor="#F7F7F7" />
        <Columns>
            <asp:CommandField ShowSelectButton="True">
            <ItemStyle Width="50px" />
            </asp:CommandField>
            <asp:BoundField DataField="id" InsertVisible="False" ReadOnly="True" SortExpression="id" Visible="true" HeaderText="ID"/>
            <asp:BoundField DataField="itemid" HeaderText="Item Code"/>
            <asp:BoundField DataField="itemdes" HeaderText="Description"/>
            <asp:BoundField DataField="Category" HeaderText="Category"/>
            <asp:BoundField DataField="uom" HeaderText="UOM"/>
            <asp:BoundField DataField="Suppprice" HeaderText="SuppPrice"/>
            <asp:BoundField DataField="taxcode" HeaderText="Tax Code"/>


        </Columns>
        <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
        <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
         <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
        <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
        <SortedAscendingCellStyle BackColor="#F4F4FD" />
        <SortedAscendingHeaderStyle BackColor="#5A4C9D" />
        <SortedDescendingCellStyle BackColor="#D8D8F0" />
        <SortedDescendingHeaderStyle BackColor="#3E3277" />
    </asp:GridView>

    </div>
   </form>
</body>

Dani AI

Generated

— three things usually break a popup->parent value pass when using MasterPages: (1) the parent control's client id is different from the server ID, (2) the popup's client-side click triggers a postback immediately after your script runs, and (3) the popup wasn't opened by script (so window.close or window.opener behave differently). Use a small, explicit API on the parent page and have the popup call that API. That avoids guessing client IDs from the popup and keeps behavior predictable.

Parent page (declare a single JS setter that uses the control's ClientID):

<script type="text/javascript">
function receiveItemFromPopup(value) {
  var tb = document.getElementById('<%= txtItemID.ClientID %>');
  if (tb) tb.value = value;
}
</script>

Popup page (call the parent's function, then close; cancel the postback):

<script type="text/javascript">
function sendSelectionToParent() {
  var val = document.getElementById('<%= txtItemName.ClientID %>').value;
  if (window.opener && !window.opener.closed && typeof window.opener.receiveItemFromPopup === 'function') {
    window.opener.receiveItemFromPopup(val);
    window.close();
  }
}
</script>

<!-- prevent server postback after the client handler runs -->
<asp:Button ID="btnSelectItem" runat="server" Text="Select" OnClientClick="sendSelectionToParent(); return false;" CausesValidation="false" />

Quick troubleshooting:

  • Inspect window.opener in the console from the popup to confirm it exists.
  • If controls are inside naming containers, ClientIDMode="Static" on the target textbox is another option.
  • If the parent needs the value server-side immediately (UpdatePanel/partial postback), write the value into a hidden field and trigger the needed postback or callback after the popup closes.

Follow these steps and the popup should reliably pass the value back.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.