Determining which button is pressed in a Web dialog

If I create a web message dialog in code:

Var md As new WebMessageDialog
md.Title = "Title Text"
md.ActionButton.Caption = "Quit"
md.CancelButton.Visible = False    
md.AlternateActionButton.Visible = True 
md.AlternateActionButton.Caption = "Don't Quit"
md.Message = "Message text"
md.Explanation ="Explanation text"

md.show

then I can get the dialog to display as expexted, but how do I determine which button has been pushed? The show function doesn’t return a value.

Thanks
S

You need to implement the ButtonPressed event of the WebMessageDialog. See here for more info:

https://documentation.xojo.com/api/user_interface/web/webmessagedialog.html#webmessagedialog-buttonpressed

When the button pressed event fires, the button they pressed is passed in.

Thanks - but I can’t find in the documentation how to do that from code. How can I implement an event from code (rather than by hand building each dialog in the IDE)?

Best regards
Steve

Use AddHandler.

  1. Right-click on WebMessageDialog in your code and select Add Method > From Event

  2. It’ll add a method to the page with the correct signature.

  3. Back in your code just after declaring your variable, put the following, replacing with the name of the method created in step 2.

AddHandler md.ButtonPressed, AddressOf <method>

  1. Inside the method that was created, at the very top, put:

RemoveHandler obj.ButtonPressed, AddressOf <method>

It’s very important to call the remove version to prevent memory leaks.

4 Likes

Excellent! Thanks so much for the pointers.

Best regards
Steve