Click here to Skip to main content
15,889,876 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi
I can open popup with data populate in GridView. It is work fine. But I could not pass back the selected data to Parent windows text Box. I have tried. I am using Master page in Parent Window.

Is there any Issue in Master Page..?

Pls advice me

Maideen

Parent Aspx page

JavaScript
<script type="text/javascript">
    var popup;
    function SelectItemDESC() {
        popup = window.open("ProductSearch.aspx", "Popup", "width=800,height=400");
        popup.focus();
        return false;
    }
</script>


Popup windows

ASP.NET
 <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="setValues()"  />

 <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();
         }

         function SendValue(val) {
             window.opener.document.getElementById("txtItemID").value = val;
             window.close();
         }

         function setValues() {
             //popup window element value
             var txt = document.getElementById("txtItemName").value;

             //parent window element to set value as
             window.opener.document.getElementById("txtItemID").value = txt;
             self.close();
             return false;
         }
     </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>


What I have tried:

I have tried the sample from Code Project "Passing value from popup window to parent form TextBox"

But I could not pass back data to main windows...
Posted
Updated 20-Apr-16 0:26am
Comments
Sergey Alexandrovich Kryukov 20-Apr-16 2:08am    
You have to pass reference to the parent to popup, because you have reference to the popup in parent.
What "sample from Code Project"? Any link? You are showing some code to the reader not knowing the code you are using, so what's the use. You need to explain the problem. Anyway, this is a simple thing.

But first of all, think about not using popups. Users don't like them, many will apply blocking in browser...
—SA
Maideen Abdul Kader 20-Apr-16 3:15am    
Thanks Alex
Yes, I am agree with you.User do not like. But our client needs this even though I have told them.
Popup code, I have given is full html code. code behind page is below

Sub SearchProducts()
Dim query As String = String.Format("SELECT id,itemid,itemdes,category,uom,suppprice,taxcode from ADM_ProductInfo where itemdes like '" & Me.txtSearch.Text & "%' or itemid='" & Me.txtSearch.Text & "' order by itemdes")
Try
Dim dt As DataTable = GetData(query)
Me.GridView1.DataSource = dt
Me.GridView1.DataBind()
Catch ex As Exception
ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "Message", "alert('Error occured : " & ex.Message.ToString() & "');", True)
Finally
cmd = Nothing
conn.Close()
End Try
End Sub

Once select the product from grid, I capture id of product into Textbox that name is "txtItemName"

Parent page has textbox name "txtItemID". From the id we can pull details from database.
Parent page has master.page. and I am using Bootstrap css and js. for designing.

Do you have any idea? pls let me know..

Thank you..

1 solution

Kindly refer sample code here. I hope this code will help you more.

Pass value from child popup window to parent page window using JavaScript[^]
 
Share this answer
 
Comments
Maideen Abdul Kader 22-Apr-16 21:27pm    
Hi Thiyagaran
Yes I have used. It works in html. But it is not working asp.net page with master. page
Any Idea?
I am using bootstrap for designing. Is there any issue in Bootstrap or Master Page.? Pls
maideen
Maideen Abdul Kader 23-Apr-16 6:16am    
HiI have done some research and found that the value of popup windows only display on Lable only. Not in text box. Pls help
Below is code

<script type="text/javascript">
function SelectName() {
if (window.opener != null && !window.opener.closed) {
var form = window.opener.document.getElementsByTagName("form")[0];
var txtName = GetElement(form, "span", "Label19");
txtName.innerHTML = document.getElementById("txtItemName").value;
}
//return false;
window.close();
}
function GetElement(parent, tagName, id) {
var elem = parent.getElementsByTagName(tagName);
for (var i = 0; i < parent.getElementsByTagName(tagName).length; i++) {
if (elem[i].id.indexOf(id) != -1) {
return elem[i];
}
}
return null;
}
</script>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900