In ASP.NET 2.0 How do I return a value from a page that is a user control and postback?

5 pts.
Tags:
.NET
Ajax
ASP.NET
JavaScript
Web development
Overview: Click a button on a page, have it popup a search page (js, ajax, whatever). The search page is nothing more than a wrapper for a user control which contains the search logic & UI - I can manipulate properties if needed. The popup has fields to search by, a search button, and a cancel button. The 2 things I need to handle are if cancel is pressed (close the popup and resume) or populate the calling page with the results of the selection from the search. Simplified: Default.aspx has a textbox (txtName), label, and one button (btnSearch). Popup.aspx has one user control which (for simplicity) returns a GUID and closes itself. Default.aspx then needs to load itself based on that GUID. Problem: If the User Control weren't there, I'd have this knocked out. What I don't know is how to get through the layers of the Popup.aspx and the User Control to get that selected value. I'm also not too sure how to cause the event to fire once the result is returned since I'd planned on using JS to open the popup. I'll be monitoring all day - Any help would be greatly appreciated. Also, I'm an ex-EE user for years. They normally let a question like this just sit. PLEASE let me know if I'm going about this the wrong way, if it's impossible, or if you have a better idea! Thank you!
ASKED: July 22, 2008  2:58 PM
UPDATED: July 22, 2008  5:53 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

If the properties of the user control are exposed with getters and setters, then they should be available to JS using dot notation. Give the control an ID and you can use document.getElementById(id).prop.

If in your situation you have 1-n results of which many can be selected, this will require a mechanism to maintain selection state, especially if the results are paginated (you don’t want an item selected on page one, have the user move to page two, and then go back to page one to find that the item is no longer selected).

I typically create an array that I will scan to add items when selected and remove items when deselected. I would then expose that array/collection/whatever as a property of the control, and access it as above.

If you opened the popup window using window.open and both Popup.aspx and Default.aspx are on the same domain, using the window handle you can capture an event in the popup window’s DOM from the context of Default.aspx, and pass it a reference to a handler that runs in Default.aspx.

Attach an event to the selection of an item or the unload event of the window or the control (something that signifies that you are done with the window, but before the control is removed from memory and its properties are no longer accessible), and pass the array of GUIDs to the handler.

That’s what I would try first.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following