OOP best practice return results to WebControls from called object

I have a WebContainer that appears in several places e.g. in WebPage, WebDialog.
Inside the WebContainer, I have several WebSearchFields which instantiates a certain WebDialog with search results in a WebListBox on Press event. This WebDialog is generic in the sense that the properties of the WebListBox inside it changes automatically based on the specific WebSearchField it was invoked from (I pass in parameters to the WebDialog Constructor method).

The above all works fine. However, I’d like to know what is the best practice, I guess from an OOP perspective, to return some action from the WebDialog to the specific WebContainer instance it was originally called from? E.g. if the user made a database ID selection from the WebListBox in the WebDialog, I’d like it to run a database query and return the results to the WebControls in the WebContainer instance the WebDialog was invoked from.

Edit: I do not know how to identify the WebContainer instance the WebDialog was called from. If I know this, I am guessing I can write a value to that a Control in that WebContainer.
e.g. MyContainer1.MyTextField = ValueFromWebDialog

instead of updating MyTextField in MyContainer2 for instance (where MyContainer1 and MyContainer2 are an instance of MyContainer)

I hope all that makes sense.

Not sure if I understand but from what I believe I understand perhaps you would want to add a handler when you instantiate the webdialog from within a WebContainer, something like this:

AddHandler appointmentDialog.Dismissed , AddressOf Self.HandleAppointmentDismissed

Where HandleAppointmentDismissed is the method where I handle the webdialog dismissed event. You could add different handlers for each webContainer that instantiates the dialog. Just rember to remove the handler after it has been used.

Another option would be to have all WebContainers which use this WebDialog implement an interface. When you initiate the WebDialog you pass the “parent” WebContainer and store that in a property of the WebDialog, which is typed as the interface. When the WebDialog needs to, it calls a method off the interface. Each WebContainer can implement whatever code it needs in that interface method. (Note: don’t create a circular memory reference by storing the parent in a child property and the child in a parent property. If you need to do this, then either use WeakRef or make sure you nil the child property when the user dismisses the WebDialog.)

A variation of this would be to have all these WebContainers inherit from a parent class which implements this method. This would be useful if some or all of the WebContainer children have the same behavior (same code). You could have that base code in the parent class, but you would still be able to override it in child classes. If you use a common parent class you don’t have to also have an interface.

Thanks this looks interesting and I think could work. So I understand that the event handler is passed to the method inside the WebContainer, from which the WebDialog was originally instantiated.
How can I pass paramters from the WebDialog dismiss event to the handle method in your example? For example, let’s say I want to pass the WebListBox.SelectedRowValue (from inside the WebDialog) to the method when the WebDialog is dismissed?

Thanks. I will need to research the first approach a bit more, but I understand in principle what is happening. If you can point me to any practical examples using this approach, I would highly appreciate it.

I’m not sure why I never thought of the second approach. Although as you say, it’s best if the method is the same or else it will need overriding in every WebContainer.

I often use a Delegate in this case. The container holds a reference to the Delegate callback of the function that I want called when the container “completes” its work. The Delegate is defined with the parameters that are important to me to receive whatever information I want back from the container.

Thanks that’s interesting…I’ve not used delegates before but did some reading in the documentation. So where would I define the delegate in this case? In the WebContainer from where the WebDialog is instantiated?
Then in the WebListBox (inside the WebDialog) SelectionChange event, I can create an object of the defined delegate type. But I would then need to use AddressOf to point it to the right method of the specific WebContainer and Invoke it. So would I still need to pass the WebContainer instance to the WebDialog when constructed the WebDialog so that it knows which instance of the WebContainer to invoke the method?