Close WebDialog from WebButton Pressed event in WebContainer

I have a WebContainer that contains a WebButton.
The WebContainer can be instantiated in more than one WebDialog. The WebButton action should close the WebDialog the WebContainer is displayed in. How can I do that?
Feels like it should be something simple, but I can’t use Self.Close in the WebButton pressed event as that would refer to the WebContainer itself.

Also I could put the WebButton in the WebDialog itself and run Self.Close which should solve it, but I was wondering if there was a way to put the button in the WebContainer.

I’m not clear on what you want o accomplish

I have made a sample project to show you what I mean. But it won’t let me upload Xojo binary files here. Any idea how I can share it?

Dropbox, onedrive, googledrive, wetransfer

You can add an Event Definition to your container, let’s call it CloseDialog
The pressed event of the Button can RaiseEvent CloseDialog
The container in your Dialog will have Self.Close in CloseDialog event.
I’m not saying this is the right/best/only option but is easy to explain. I hope this is what you want.

That’s great thanks - seems like what I want! So essentially the button press event subsequently fires a pre-defined custom event belonging to the container. However what I do not understand is if CloseDialog is an Event Definition belonging to the container, then calling Self.Close would attempt to close the container and not the WebDialog?

Self.Close is not the same as Me.Close

Oops…although I knew that…I got it confused for a moment.
Anyway, here’s the sample file, but I think what you suggested would work so will try that. Thanks

Let me know if you get it to work.

A little annoying that there seems to be a bug with Event Definition. I can’t type anything into the code editor window. Plus the blinking text cursor is in the margin. I would have expected others to open a ticket about this so seems like it’s just affecting me? I will raise a ticket.

xojo_event definition bug

In an event definition** you can’t type anything. You can only define the Event name, parameters and return value (if any) trough the inspector.

** you define an event name that a subclass is to be using

Implementing (e.g. using, handling) an event is different you can WebPage → RMB → Add event handler

1 Like

Nope, that is how things work.
You add an Event Definition for your Container and when you use the container you select the Event.

Using your example as the base:
Add an event to your Container1 named CloseDialog

add to the Button a pressed event with code RaiseEvent CloseDialog

On your container11 in the webdialog, add the CloseDialog event
and put Self.Close in that event

Now your app works as you want: (15)

1 Like

Thanks a lot that all works as intended! As you can tell, I’m new to defining my own events. But something new I’ve learnt today.

We are all leaning all the time. The forum has great people willing to help :slight_smile:

1 Like