WebContainers and WebPages Instances

Hi Team,

I am new to xojo and i was wondering how can a webcontainer talk to an instance of a webpage.

If i have a webcontainer in a webpage i can say webpage.control.method but if i instantiate a webpage webpage.control.method does not work so how can the webcontainer know which webpage is in. Sorry for the easy question. TIA.

It’s not the best approach, but you can use the webcontainer’s Parent property to get a reference to the webpage.

if self.Parent IsA mywebpage then

The prefered approach is to make it object oriented and draw a sharp line between the webpage and the webcontainer. Communication between them happens via methods and events that the webcontainer defines. Ie., the webcontainer publishes an API that the webpage can use, but is otherwise opaque. The webpage doesn’t need to know anything about the webcontainer other than the API. It doesn’t need to know anything about the webcontainer internals. Also, the webcontainer doesn’t need to know anything about the webpage it is on.

The webpage talks to the webcontainer by calling methods that the webcontainer has made public.

The webcontainer talks to the webpage by raising events. The webpage implements those events with whatever code it wants. The webcontainer doesn’t know or care what that code does.


For an example on how to do communicate from a container to its parent in a reusable way there is a project at Example Projects/Platforms/Desktop/Custom Controls/OKCancelContainer.xojo_binary_project

(It’s not a Web project, but the idea is exactly the same: use Event Definitions)