how do i send data from a popup window back to the calling page in ASP.NET 2.0? (VB)

I have a main page that needs a textbox filled with a product ID, since there are so many products, I decided to create a popup window with a treeview that allows a user to select a product  from a selected category and click on the product name (a link or button or anything) that would post the productId back to the main page.
I've seen examples of doing this with session variables but that seems a bit quirky.
Is there any simple way of posting data back to a calling page from a popup window?
Thanks!
bd9000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
>I've seen examples of doing this with session variables but that seems a bit quirky.
it's the best way, and I don't see anything quirky about that?
you might want to check out to find javascript examples instead, but those will eventually fail to be cross-browser compatible...
0
Bane83Commented:
Very easy with javascript.  Add this to a the link/button/whatever's client event that fires when you make the selection:

window.opener.document.getElementById('TextboxToHoldProductID.ClientID').value = [this.value];

You'll likely have to hard code the TextboxToHoldProductID.ClientID string as there's no way that I can think of right now to get the ClientID from window to the other (unless you pass it in using a querystring, so you might want to consider this instead of hardcoding --> window.open('MyPopup.aspx?ControlID=" + this.id, ....)).

Also [this.value] is to be replaced with whatever needs to be filled in the textbox.  This is dependent on the control you use.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bd9000Author Commented:
I've seen in the examples about registering popup pages - do I need to do this with ASP.Net 2.0 even though I'm not actually doing a postback (w/JavaScript)?

- on another note, I've found that as long as you use GetElementByID, most browsers (IE, FF, Opera, NS & Safari) will work fine. I think JavaScript is pretty much the defacto standard now - anyone using an ancient browser probably can't afford our products anyway :)
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Bane83Commented:
Not sure what you mean about registering, but I've done this exact thing before and I didn't have to do anything other than a window.open() in my main window and window.opener.document.getElementById()... in the popup.
0
bd9000Author Commented:
Ok, I got it to work. I discovered that the button control on the main page causes a reload of the main page when clicked even if the UseSubmitBehavior=false and CausesValidation=false (by design, I presume), so I added an HTML button to the form and put the popup opening function in it's OnClick event (not documented by VS2005) to open the popup window without a page refresh/reload.

Here's the final working code (test page) with 2 different buttons to show that the second one does not cause a page refresh of the calling page.
<!-- Main Calling Form -->
<form id="frmMain" runat="server">
<div>
<asp:Button ID="btnOpenPopUp" runat="server" CausesValidation="False" EnableViewState="False" OnClientClick="window.open('popup2.aspx');" Text="Open PopUp" UseSubmitBehavior="False" />
<br />
<input id="btnOpenPopUp2" type="button" value="Open PopUp 2" OnClick="javascript:window.open('popup2.aspx');" />
<br />
<asp:TextBox ID="txtReturnValue" runat="server"></asp:TextBox>
</div>
</form>
 
<!-- PopUp Form -->
<form id="frmPopUp" runat="server">
<div>
<asp:Button ID="btnReturnValue" runat="server" Text="Return Value And Close" CausesValidation="False" EnableViewState="False" OnClientClick="window.opener.document.getElementById('txtReturnValue').value = [window.document.getElementById('txtValueToReturn').value];window.close();" UseSubmitBehavior="False" />
<br />
Enter value to return to main form
<br />
<asp:TextBox ID="txtValueToReturn" runat="server">123</asp:TextBox>
</div>
</form>

Open in new window

0
Bane83Commented:
The postback is because asp:Buttons render as submit buttons.

In order to disable the postback, you would need to add OnClientClick="return false;" to the button.  This cancels the postback event.
0
bd9000Author Commented:
Sounds good! Thanks again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.