Web 2.0 Message Dialog and Web Dialog Title Style

It looks like you’re trying to use the example from the Desktop version of MessageDialog. You should look at the documentation for WebMessageDialog. Although an example is missing from the docs, I just whipped up an example for you.

I created a PushButton on my WebPage, and in the Pressed event, I added the following code:

Var d As New WebMessageDialog                  // declare the MessageDialog object
d.ActionButton.Caption = "Save"
d.CancelButton.Visible = True               // show the Cancel button
d.AlternateActionButton.Visible = True      // show the "Don't Save" button
d.AlternateActionButton.Caption = "Don't Save"
d.Message = "Do you want to save changes to this document before closing?"
d.Explanation = "If you don't save, your changes will be lost. "

AddHandler d.ButtonPressed, WeakAddressOf dialogButtonPressed

d.Show                            // display the dialog

You’ll notice this is very similar to the Desktop code, but there’s no code to handle which button is clicked. Instead, we have an AddHandler line which will call the dialogButtonPressed method. Here’s the definition for that method:

Private Sub dialogButtonPressed(sender as WebMessageDialog, button as WebMessageDialogButton)
  Select Case button                               // determine which button was pressed.
  Case sender.ActionButton
    // user pressed Save
    button1.Caption = "Saved!"
  Case sender.AlternateActionButton
    // user pressed Don't Save
    button1.Caption = "Unsaved!"
  Case sender.CancelButton
    // user pressed Cancel
    button1.Caption = "Canceled!"
  End Select
End Sub

Upon running this example, clicking the button shows the WebMessageDialog. When you click one of the WebMessageDialogButtons, the dialog is dismissed and the caption of the button is changed based on the selection.

The easiest way, however, is to add a “Message Dialog” to your page from the Library and implement the ButtonPressed event there.

2 Likes