Xojo Web, adding event handlers to dynamically created containers

I have a property within my web page called CurrentContainer. It’s type is webcontainer.

I use embedwithin to add a container to the page and assign it to the currentcontainer property.

I am using an external library which fires events when a control looses focus. This library needs to send events to the webpage. I have tried using addhandler to add an event handler and I have also tried subclassing the container as a type with the events defined. In either case the events defined within the container do not show up.

Is this actually possible or am I taking the wrong approach?

Example of useing a own Event

Sub Opening() Handles Opening
  Var c As New CC
  CC1 = c
  AddHandler CC1.Hello, AddressOf Hello
End Sub
Public Sub Hello(c As CC)
  MessageBox "Hello"
End Sub
Public Property CC1 as CC

ContainerControl Named CC
event definition

Event Hello()
Button Click
Sub Pressed() Handles Pressed
  RaiseEvent Hello
End Sub
1 Like

Hi MarkusR - thank you for your reply. Is the event Hello a definition?

I have the two event definitions PassGotFocus and PassLostFocus within the container.

I have just tried to recreate the above and the two events are not available within the following code: -
var con as new Dashboard

con.LockLeft = true
con.LockTop = True
con.LockBottom = True
con.EmbedWithin(self, 120, self.top + offset, 1000, 650)

AddHandler con.Passgotfocus addressof test() // This line does not autotab to the event…

currentContainer = con

The error is “Type Dashboard.Dashboard” has no member named “Passgotfocus”

Is Dashboard the control you’re embedding or the parent control you’re embedding within? Generally, I’m used to the dashboard being the container holding a number of controls. You would want to add the handler to the dynamic instance you create.

Where is this code located?
What are the names of your parent control, and the control you’re embedding?

Hi Tim,
Dashboard is the container. It is a sequence of buttons to navigate the user to the correct location within the app.

The web page is named MainWebPage.

Dashboard, Details, Customers are all containers, which can be embeded within the Mainwebpage. Only one at a time and they are assigned to the variable CurrentContainer.

I have just put together this sample which demonstrates the issue.

Public Sub DisplayContainer()

if currentContainer <> nil then
end if

var con as WebContainer

select case index

case 0
var dash as new dashboard
AddHandler con. <------ event isn’t available. It is defined in dashboard.
con = new Dashboard
case 1
var det as new Details
AddHandler det. <----- event isn’t available. It is defined in Details.
con = det
case 2
con = new Customers

case else
MessageBox (“Display Container: Index not yet handled”)
index = index - 1 // reset back to previous value
end select

con.LockLeft = true
con.LockTop = True
con.LockBottom = True
con.EmbedWithin(self, 120, self.top + 80, 650, 650)
currentContainer = con

End Sub

This is why you’re getting event isn’t available. The custom events you’ve defined are not on WebContainer, they are on your subclass.

From what you describe, I’d think something like this:

var oDash as new Dashboard
AddHandler oDash.PassGotFocus, WeakAddressOf SomeHandlerOnMainWebPage

CurrentContainer = oDash

Sorry typo when creating the example: -
var dash as new dashboard
AddHandler con.

should have read: -
var dash as new dashboard
addHandler dash.

Event is still not present.

Don’t rely on Auto Complete to tell you whether or not code works. Auto Complete has problems especially with AddHandler.

Yeah I’ve tried that - I have typed in and even copied and pasted the event name. I am getting an error telling me the event doesn’t exist.

If you want to privately send me the project I can take a look.
(I’m assuming by third party library you mean TP_WebKit)

1 Like

Sent you a pm, yes the third party library is TP_Webkit.

Problem was solved by Tim. I’d forgotten to put a parameter in the handler which is the type of class raising the event.

1 Like