Reputation: 1454
I have a popup with a gridview on it and I would like to populate a textbox on the parent form with the text from the selected row/column. The code I am using below works but it refreshes the popup window with the parent form and populates the textbox in the popup. Is there way that when "Select" is pressed it closes the popup and adds the text to the textbox on the parent form?
<asp:HyperLinkField DataNavigateUrlFields="ID, ProductCode, Item, RetailCost" HeaderText="Select"
DataNavigateUrlFormatString="Default.aspx?ID={0}&ProductCode={1}&Item={2}&RetailCost={3}"
Text="Select" />
ProductTextBox.Text = Request.QueryString("Item")
Upvotes: 0
Views: 1088
Reputation: 30727
You should be able to fire a Javascript method in your parent window from your popup window.
So for example, in your parent window create a function that you want to call from your child popup:
function FillTextFromPopup(text){
// populate your text here...
}
You can call now call this function from your child popup window, and also close your popup by adding some code like this to your button:
onClick="window.opener.FillTextFromPopup('yourTextString'); window.close();"
Using this method, rather than directly accessing the textbox on the parent, such as window.opener.document.getElementById('yourTextBox')
is also cleaner as any changes you make to the parents textbox's and possible ID's don't have to be carried through to the child popup too.
Upvotes: 1