Class

WebDialog


Description

A WebDialog is a small dialog window that displays as a sheet, palette or modal dialog within a web page.

Methods

Name

Parameters

Returns

Shared

AddControl

Child As WebControl

Close

ControlAt

Index As Integer

WebControl

Controls

Iterable

ExecuteJavaScript

Script As String

GotoURL

Url As String, inNewWindow As Boolean = False

Hide

SetFocus

Show

UpdateBrowser

Property descriptions


WebDialog.ContextualMenu

ContextualMenu As WebMenuItem

If you assign a WebMenuItem to the control, it will be displayed when the user right-clicks the control.

On a WebPage, you can disable/remove the default contextual menu by an empty WebMenuItem class object to this property.

This code populates a contextual menu in the Shown event of the control.

Var menu As New WebMenuItem

menu.AddMenuItem("One")
menu.AddMenuItem("Two")
menu.AddMenuItem("Three")
Me.ContextualMenu = menu

The menu selection is then handled by the ContextualMenuSelected event when the user right-clicks on the control. For example, it can be of the form:

Select case hitItem.Value
Case "One"
  MessageBox("One")
Case "Two"
  MessageBox("Two")
Case "Three"
  MessageBox("Three")
End Select

WebDialog.ControlID

ControlID As String

Identifies the control on a per session basis.

This property is read-only.


WebDialog.Enabled

Enabled As Boolean

When True the WebControl is drawn enabled and responds to user action. When False, the control appears as disabled and does not respond to user actions.

In the case of WebTimer, when set to False this disables and stops the WebTimer. When set to True, it starts the WebTimer.

Disable a button when a check box value changes:

If AllowSaveCheckBox.Value Then
  SaveButton.Enabled = True
Else
  AllowSaveButton.Enabled = False
End If

WebDialog.Height

Height As Integer

The height (in pixels) of the control.


WebDialog.Indicator

Indicator As Indicators

The color scheme for the control.

When a WebButton's Default or Cancel properties are True, the Indictor property is ignored as Default and Cancel buttons have a default indicator.


WebDialog.LastControlIndex

LastControlIndex As Integer

The index of the last WebControl on the WebView.


WebDialog.LayoutDirection

LayoutDirection As LayoutDirections

The direction in which WebContainer controls will flow when added at runtime to a layout whose LayoutType is set to Flex.


WebDialog.LayoutType

LayoutType As WebView.LayoutTypes

The type of layout dictates whether controls are positioned at fixed locations or can move to accommodate changes to the bounds of the WebView, in the latter case, only for WebContainer controls that are added at runtime to a layout whose type is set to Flex.


WebDialog.Left

Left As Integer

The position of the left side of the WebUIControl in pixels, relative to the web page.

This property is read-only.


WebDialog.LockBottom

LockBottom As Boolean

Determines whether the bottom edge of the control should stay at a set distance from the bottom edge of the parent control, if there is one, or the owning web page.

This property is read-only.


WebDialog.LockHorizontal

LockHorizontal As Boolean

LockHorizontal overrides LockLeft and LockRight. It allows you to proportionally lock a control's position to the center of its parent control (or web page).

This property is read-only.

For example, if you place a control in the center of the page and sets both LockHorizontal and LockVertical, the control will stay in the center of the page.


WebDialog.LockLeft

LockLeft As Boolean

Determines whether the left edge of the control should stay at a set distance from the left edge of the parent control, if there is one, or the owning web page.

This property is read-only.


WebDialog.LockRight

LockRight As Boolean

Determines whether the right edge of the control should stay at a set distance from the right edge of the parent control, if there is one, or the owning web page.

This property is read-only.


WebDialog.LockVertical

LockVertical As Boolean

LockVertical overrides LockTop and LockBottom. It allows you to proportionally lock a control's position to keep it centered within the parent control or web page.

This property is read-only.

For example, if you place a control in the center of the page, and sets both LockHorizontal and LockVertical, the control will stay in the center of the page.


WebDialog.MinHeight

MinHeight As Integer

Sets the minimum allowed height of the WebDialog in pixels.

This property is read-only.


WebDialog.MinWidth

MinWidth As Integer

Sets the minimum allowed width of the WebDialog in pixels.

This property is read-only.


WebDialog.Name

Name As String

The name of the control.

This property is read-only.


WebDialog.Page

Page As WebPage

Identifies the web page that contains the control.

This property is read-only.


WebDialog.Parent

Parent As WebControl

Used to get the control's parent control or page. If the parent control is a WebContainer, then it returns the WebContainer. If it is on a WebPage, it returns the WebPage.

This property is read-only.


WebDialog.Resizable

Resizable As Boolean

If True the WebDialog will have a resize widget and will be resizable by the user.


WebDialog.Style

Style As WebStyle

The WebStyle for the control.

In the Pressed event of a WebButton, set the text to bold:

Var style As New WebStyle
style.Bold = True
Me.Style = style

WebDialog.TabIndex

TabIndex As Integer

The WebUIControl's control's position in the Tab Order. The control with a TabIndex of 0 is the first WebUIControl to get the focus when the page opens in the browser.

This example sets the control's TabIndex.

Me.TabIndex = 2

WebDialog.Title

Title As String

The title of the dialog box.This is only used for Palette dialogs.


WebDialog.Tooltip

Tooltip As String

Text of a message displayed as a tooltip.

The tip is displayed when the user places the mouse on the control and leaves it there.

This code in the Shown event of a Button sets the tooltip:

Me.Tooltip = "Save changes"

WebDialog.Top

Top As Integer

The top of the control in local coordinates relative to the web page.

This property is read-only.


WebDialog.Visible

Visible As Boolean

If True, the control is drawn. If False, it's not.

Hide a control based on a checkbox setting:

If ShowEmailCheckbox.Value Then
  EmailField.Visible = True
Else
  EmailField.Visible = False
End If

WebDialog.Width

Width As Integer

The width (in pixels) of the web control.

This code in the Shown event handler increases the size of the control:

Me.Width = Me.Width + 50

Method descriptions


WebDialog.AddControl

AddControl(Child As WebControl)

Adds the passed Control to the WebView.

This code adds a WebTextField to the page:

Var tf As New WebTextField
tf.Left = 100
tf.Top = 50
tf.Enabled = True
Self.AddControl(tf)

WebDialog.Close

Close

Removes the control from the page.


WebDialog.ControlAt

ControlAt(Index As Integer) As WebControl

Returns the WebControl at the index passed.


WebDialog.Controls

Controls As Iterable

Allows you to iterate through the controls on the layout.


WebDialog.ExecuteJavaScript

ExecuteJavaScript(Script As String)

Executes the JavaScript passed. The JavaScript passed can call a JavaScript function in a WebPageSource control.

The Xojo web framework uses EcmaScript 6 which is more strict than previous versions of JavaScript. For more details, see the EcmaScript 6 documentation.

This code in the Pressed event of a Button displays an alert using JavaScript:

Me.ExecuteJavaScript("alert('Hello!');")

This code will select the text in a WebTextField (or WebTextArea):

WebTextField1.ExecuteJavascript("document.getElementById('" + _
  WebTextField1.ControlID + "_inner').select();")

WebDialog.GotoURL

GotoURL(Url As String, inNewWindow As Boolean = False)

Opens the passed URL in place of the current web page or downloads a file. If InNewWindow is True, the browser is asked to open the URL in a new window.

If the browser has popup windows disabled and InNewWindow is True, the method silently fails and the page is not shown.

If InNewWindow is False, the running web app is replaced with the specified URL. If you want to display an external web site within your web app, use the WebHTMLViewer control.

Display a web site in a new popup window:

Me.GotoURL("http://www.wikipedia.org", True)

WebDialog.Hide

Hide

Hides the dialog box. The dialog box is still in memory and accessible via code.

You can use this on a button click event to hide the dialog. If you hide a dialog with the Hide method, you can display it again by calling Show.

Hide the dialog:

Self.Hide

WebDialog.SetFocus

SetFocus

Sets the focus to the Control.

This code checks for a required value when a button is pressed:

If UserNameField.Value = "" Then
  MessageBox("Please enter your UserName.")
  UserNameField.SetFocus
  Return
End If

WebDialog.Show

Show

Shows the dialog if it was not yet open or is just hidden.

Show a dialog:

MyDialog.Show

WebDialog.UpdateBrowser

UpdateBrowser

Forces the current values of the control to be sent to the browser.

This method is useful when you are computing values in a loop and wish to update the browser immediately rather than wait until the current method ends.

This code iterates through a RowSet of database rows, updates a ProgressBar and then forces the updated ProgressBar to be sent to the browser via UpdateBrowser.

ProgressBar1.Maximum = SalesData.RowCount
For Each row As DatabaseRow in SalesData
 AnalyzeSales(row)
 ProgressBar1.Value = ProgressBar1.Value + 1
 ProgressBar1.UpdateBrowser
Next

Event descriptions


WebDialog.Closed

Closed

The control has been removed from the browser either because the page has closed or the control's Close method was called.


WebDialog.ContextualMenuSelected

ContextualMenuSelected(hitItem As WebMenuItem)

Called when a contextual menu item is selected. This selected item is contained in hitItem.

This code populates a contextual menu in the Opening event of a WebToolbar:

Var menu As New WebMenuItem

menu.AddMenuItem("One")
menu.AddMenuItem("Two")
menu.AddMenuItem("Three")
Me.ContextualMenu = menu

The menu selection is then handled by the ContextualMenuSelected event when the user right-clicks on the control. For example, it can be of the form:

Select case hitItem.Value
Case "One"
  MessageBox("One")
Case "Two"
  MessageBox("Two")
Case "Three"
  MessageBox("Three")
End Select

WebDialog.Dismissed

Dismissed

Called when the dialog is dismissed by calling its Hide or Close methods.

Consider a dialog, MyDialog, which has a single button with this code in its Action event handler:

Self.Close

With this dialog dragged onto a web page, you can display it using this code (probably on the Action event handler of a button):

MyDialog1.Show

When the dialog is closed, the Dismissed event handler is called. This code displays a simple message to indicate it was closed:

MessageBox("Dialog is closed.")

In this event handler, you can also access properties of the dialog to check values that were entered or buttons that were pressed. For example, If there was a TextField on the dialog, you could get its value in the Dismissed event handler like this:

Var text As String
text = Me.TextField1.Text
MessageBox("Text=" + text)

Similarly, if your dialog has multiple buttons and you want to know which one was clicked, you will have to save that information into a property you can check. For example, you can add a ButtonClicked As WebButton property to the dialog. In an OK button (named OKButton), you then use this code to indicate that the OK button was pressed:

ButtonClicked = Me
Self.Close

In a Cancel button (named CancelButton), you would use the same code:

ButtonClicked = Me
Self.Close

Now when the dialog is closed, you can check the ButtonClicked property in the Dismissed event handler to see which button was used to close the dialog:

Select Case Me.ButtonClicked
Case Me.OKButton
  MessageBox("OK selected.")
Case Me.CancelButton
  MessageBox("Cancel selected.")
End Select

WebDialog.Opening

Opening

The control has been created and the page is opening but has not been sent to the browser yet.

The Opening event handler can be used to initialize non-visual properties and settings for controls.

In most cases, you should use the Shown event to initialize controls.


WebDialog.Overflowed

Overflowed

The area (in pixels) by which WebContainers have overflowed the bounds of a WebView whose LayoutType is set to Flex.


WebDialog.Resized

Resized

The WebView has been resized either because the user resized the browser window or the WebView was resized at runtime via code.


WebDialog.Shown

Shown

The control has appeared on the currently displayed page. This could be because its parent page just finished loading, its parent page has come to the foreground or the control is now visible having been previously invisible because it or its parent control's Visible property has been set to True.

Use the Shown event for initializing your controls or doing anything that would interact with other controls or user interface elements on the web page instead of the Opening event.

Note

This event is the web equivalent to the DesktopWindow.Activated event.

This code in the Shown event of a WebListBox adds 2 rows with 3 columns:

Me.RemoveAllRows
Me.AddRow("Row 1", "Bob", "Roberts")
Me.AddRow("Row 2", "Barb", "Reynolds")

This example sets the text of a label:

If Session.LoggedIn Then
  Me.Value = "Welcome!"
Else
  Me.Value = "Welcome, " + Session.UserName
End If

Notes

WebDialogs can only contain controls that are subclasses of WebControl.

To display a dialog on your page, drag it to the Web Page Layout Editor or instantiate one in code. You can then display it by calling the Show method:

MyDialog.Show

In the dialog itself, you should have a way to close it, usually with a button with code like this:

Self.Close

When the dialog is closed, the Dismissed event handler (for the dialog on the web page) is called. There you can perform your actions.

Keep in mind that dialogs are not modal and do not stop your code from running. After calling MyDialog.Show, the next line of code will run. Use the Dismissed event handler to process the results from the dialog.

Dialogs can remain in view, even as a page is hidden from view. However, once a page is closed (rather than hidden) any dialogs attached to it are also removed.

For simple dialogs, you can instead use the MessageBox method.


Differences between dialogs in web and desktop applications

There are two important differences between dialogs in web applications versus desktop applications. The first is that web dialogs are a specific type project item whereas in a desktop application project they are a window with the Frame property set to a particular value. The other more important difference is that unlike in a desktop project, dialogs in a web application are asynchronous.

After creating a WebDialog by clicking Add Dialog in the Project Editor's command bar, you must add the dialog to any web page in front of which, you wish to show the dialog. All dialogs you add to your project will show up in the Controls pane of the WebPage Editor as they are treated, for the most part, like any other control on a webpage. To add the dialog to your page, drag it from the Controls pane to the WebPage. It will appear in the list of controller objects list at the bottom of the editor. You can then double-click the dialog to add code to its events.


Dynamically displaying a dialog

At times, you may need to display a different dialog at runtime. For example, you may want to use a different dialog to display when the user is on a mobile device.

This example dynamically displays a dialog, MyDialog, which has a single button with this code in its Action event handler:

Self.Close

On a button on the web page, you can display the dialog like this:

Var d As New MyDialog
AddHandler d.Dismissed, AddressOf DismissedHandler
d.Show

DismissedHandler is a method on the web page declared like this:

Sub DismissedHandler(d As WebDialog)
  MessageBox("Dialog closed!")
End Sub

Note

Dynamically created Dialogs that are closed by calling Close cannot be shown again until you create a new instance.

Sample code

Consider a dialog, MyDialog, which has a single button with this code in its Action event handler:

Self.Close

With this dialog dragged onto a web page, you can display it using this code (probably on the Action event handler of a button):

MyDialog1.Show

When the dialog is closed, the Dismissed event handler is called. This code displays a simple message to indicate it was closed:

MessageBox("Dialog is closed.")

Compatibility

Web projects on all supported operating systems.

See also

WebView parent class; MessageBox, WebPage, WebHTMLViewer, Window classes.