Add event handler programmatically

I have a WebDialog that instantiates a WebContainer and displays it using the WebContainer EmbedWithin method. The WebContainer has a declared Event Definition. How can I add the event handler to the instantiated WebContainer and implement it programmatically?

See AddHandler.

When I instantiate the WebDialog, I pass in the WebContainer as a parameter with which the WebDialog constructor initialises a Container property of type WebContainer.
The Container property could be of any of my subclasses of WebContainer.
I added the CloseDialog Event Definition in each Container. I have a button in each Container to raise that event on press event.
Then I tried adding the following handler using casting after instantiating the WebDialog:

Session.EditDialog = New EditRecordWebDialog(New MyContainer)
AddHandler MyContainer(Session.EditDialog.Container).CloseDialog, AddressOf CloseDialogHandler

However, it is not recognising the CloseDialog Event. Any ideas?

1 Like

Sorry it was a silly syntax error. The above works fine :slight_smile: