How to call WebPage method from an embedded container

I have a bunch of WebContainers, embedded within WebContainers on a page. I want them to be able to call a Method on the current WebPage where they live.

What is the best way to navigate to page methods/variables from embedded controls?

Here’s some terrible example of some code that doesn’t work for me…

Var my_page As WebPage(main_page)

There is a Boolean on the page that I want to toggle from a method (timer.action) that lives autonomously in the embedded container controls. TIA for your assistance.

Your WebContainers should raise events to communicate outward. You then implement Event Handlers on the instances of the containers on the page, just like you’d implement the Pressed event of a WebButton.

Example project to show how to use custom events: EventExample.xojo_xml_project


That makes perfect sense - much more OOP-like :slight_smile: Bummer I can’t get to that link you sent me though.

1 Like

Hi Tim, thanks for that example, which works really well when physically adding a subclass of a container to another container. However, I’ve got the following scenario and I hope I can get more of your help…

  • I have several columns on my page, ‘ColumnContainer_class’ (subclass of WebContainer).
  • Each of these columns are programmatically filled with ‘boxes’ (also WebContainers).
  • Each of these ‘boxes’ has a timer that refreshes elements of its own UI, and looks outside itself to the App for variable updates etc.
  • I have a method within the ‘box’ container that evaluates, and then wants to send a message (value) out of itself to a method in the page.

I’ve tried creating an Event Definition and naming it “TriggerPageMethod”. Then when I create the box and embed it within the column container I wasn’t sure how to implement a ‘receiver’ in the column class to listen.

I tried using:
AddHandler my_instantiated_box.TriggerPageMethod, AddressOf a_method_in_column_container
which compiles, but I don’t see it trigger.

So, how does a programmatically embedded container control communicate up thru the chain? It’d be great to be able to send messages to the container housing the embedded control, and also to reach past it to the parent WebPage to send it messages as well. Thanks!

Var p as myMage = myMage(Self.Parent)

Thanks @Vigia_Lin that got me to the place I needed. With the container inside a container inside a rectangle I just needed to add a few more .Parents onto the path :+1:t2:

Var p as main_page = main_page(Self.Parent.Parent.Parent)
p.columns_need_refresh = TRUE