# Determining which button is pressed in a Web dialog

**URL:** <https://forum.xojo.com/t/determining-which-button-is-pressed-in-a-web-dialog/77960>\
**Category:** Web\
**Created:** [November 2, 2023, 10:39pm UTC](https://forum.xojo.com/t/determining-which-button-is-pressed-in-a-web-dialog/77960 "2023-11-02T22:39:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Johnson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/b2d939/32.png) [@Steve\_Johnson](https://forum.xojo.com/u/Steve_Johnson)\
**Post date:** [November 2, 2023, 10:39pm UTC](https://forum.xojo.com/t/determining-which-button-is-pressed-in-a-web-dialog/77960/1 "2023-11-02T22:39:08Z")

</div>

If I create a web message dialog in code:

```auto
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

---

<div class="post-metadata">

**Author:** ![Edward\_Kidwell](https://forum.xojo.com/user_avatar/forum.xojo.com/edward_kidwell/32/14856_2.png) [@Edward\_Kidwell](https://forum.xojo.com/u/Edward_Kidwell)\
**Post date:** [November 2, 2023, 10:56pm UTC](https://forum.xojo.com/t/determining-which-button-is-pressed-in-a-web-dialog/77960/3 "2023-11-02T22:56:01Z")

</div>

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](https://documentation.xojo.com/api/user_interface/web/webmessagedialog.html#webmessagedialog-buttonpressed)

---

<div class="post-metadata">

**Author:** ![Greg\_O](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o/32/22785_2.png) [@Greg\_O](https://forum.xojo.com/u/Greg_O)\
**Post date:** [November 2, 2023, 10:56pm UTC](https://forum.xojo.com/t/determining-which-button-is-pressed-in-a-web-dialog/77960/4 "2023-11-02T22:56:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve\_Johnson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/b2d939/32.png) [@Steve\_Johnson](https://forum.xojo.com/u/Steve_Johnson)\
**Post date:** [November 2, 2023, 11:13pm UTC](https://forum.xojo.com/t/determining-which-button-is-pressed-in-a-web-dialog/77960/5 "2023-11-02T23:13:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [November 2, 2023, 11:59pm UTC](https://forum.xojo.com/t/determining-which-button-is-pressed-in-a-web-dialog/77960/6 "2023-11-02T23:59:43Z")

</div>

Use AddHandler.

---

<div class="post-metadata">

**Author:** ![Greg\_O](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o/32/22785_2.png) [@Greg\_O](https://forum.xojo.com/u/Greg_O)\
**Post date:** [November 3, 2023, 12:20am UTC](https://forum.xojo.com/t/determining-which-button-is-pressed-in-a-web-dialog/77960/7 "2023-11-03T00:20:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Steve\_Johnson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/b2d939/32.png) [@Steve\_Johnson](https://forum.xojo.com/u/Steve_Johnson)\
**Post date:** [November 3, 2023, 10:42am UTC](https://forum.xojo.com/t/determining-which-button-is-pressed-in-a-web-dialog/77960/8 "2023-11-03T10:42:53Z")

</div>

Excellent! Thanks so much for the pointers.

Best regards  
Steve
