Class

WebPage


Description

A page of the application. This is the equivalent of a DesktopWindow in a desktop application.

Events

Name

Parameters

Returns

ContextualMenuSelected

hitItem As WebMenuItem

Hidden

Opening

Overflowed

width As Integer, height As Integer

Resized

Shown

Property descriptions


WebPage.AllowTabOrderWrap

AllowTabOrderWrap As Boolean

When True If True, tabbing between focusable controls will wrap between the last control in the tab order and the first. The default is True.

This property is read-only.

This is a design-time only property. It should be set to False for webpages that will be used by users who depend on accessibility settings that allow them to tab to the browser's toolbar controls.


WebPage.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.Text
Case "One"
  MessageBox("One")
Case "Two"
  MessageBox("Two")
Case "Three"
  MessageBox("Three")
End Select

WebPage.ControlCount

ControlCount As Integer

The number of controls on the WebPage.

This property is read-only.


WebPage.ControlID

ControlID As String

Identifies the control on a per session basis.

This property is read-only.


WebPage.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

WebPage.Indicator

Indicator As Indicators

The color scheme for the control.


WebPage.IsImplicitInstance

IsImplicitInstance As Boolean

If True, the WebPage has been instantiated implicitly, for example, by referring to one of its properties.

This property is read-only.


WebPage.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.


WebPage.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.


WebPage.MinimumHeight

MinimumHeight As Integer

The minimum height of the WebPage. While we cannot prevent the user's browser from resizing too small, we can prevent the content from doing so. If the browser window is smaller than the content, scroll bars will appear.


WebPage.MinimumWidth

MinimumWidth As Integer

The minimum width of the WebPage. While we cannot prevent the user's browser from resizing too small, we can prevent the content from doing so. If the browser window is smaller than the content, scroll bars will appear.


WebPage.Name

Name As String

The name of the control.

This property is read-only.


WebPage.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

WebPage.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

WebPage.Title

Title As String

The title of the window. The title that appears in the browser is the title fo the currently displayed page. As pages are shown, the title updates accordingly.

Set the title fo the page based on the user's log in name (saved in a UserName property that was added to the Session class):

Self.Title = "Welcome, " + Session.UserName

WebPage.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"

WebPage.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

Method descriptions


WebPage.AddControl

AddControl(Child As WebControl)

Adds the passed Control to the WebView.

To remove a control, call its Close method.

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)

WebPage.Close

Close

Closes the web page.


WebPage.ControlAt

ControlAt(Index As Integer) As WebControl

Returns the WebControl at the index passed.


WebPage.Controls

Controls As Iterable

Allows you to iterate through the controls on the layout.

Note

This does not include non-control object instances. For that, use the Objects method.

This example counts the number of controls on the current page by iterating through them.

Var count As Integer
For Each cntrl As WebControl In Self.Controls
  count = count + 1
Next
MessageBox("This page has " + count.ToString + " controls.")

This example clears all checkboxes on the page:

For Each cntrl As WebControl In Self.Controls
  If cntrl IsA WebCheckBox Then WebCheckBox(cntrl).Value = False
Next

WebPage.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();")

WebPage.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)

WebPage.LastControlIndex

LastControlIndex As Integer

Returns the index of the last WebControl added to the page.


WebPage.Objects

Objects As Iterable

Allows you to iterate through all the non-control object instances on the dialog.

Note

This does not include controls. For that, use the Controls method.


WebPage.RemoveControl

RemoveControl(control As WebUIControl)

Removes the control from the WebPage.


WebPage.ScrollTo

ScrollTo(x As Integer, y As Integer)

Scrolls the window to the specified coordinates.

This sets the scroll position for ALL WebPage.

This code scrolls to the top of the window.

Self.ScrollTo(0, 0)

WebPage.SetFocus

SetFocus

Sets the focus to the Control.

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

If UserNameField.Text.IsEmpty Then
  MessageBox("Please enter your UserName.")
  UserNameField.SetFocus
  Return
End If

WebPage.Show

Show

Displays the page in the current browser window.

If the page is still open in this session from a previously call to Show, the page is shown with its current state.


WebPage.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 WebProgressBar and then forces the updated WebProgressBar 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


WebPage.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.Text
Case "One"
  MessageBox("One")
Case "Two"
  MessageBox("Two")
Case "Three"
  MessageBox("Three")
End Select

WebPage.Hidden

Hidden

The control is about to become no longer visible. This could be because the page is being closed, is being replaced as the foreground page by another page or because the control or a parent control's Visible property has been set to False.

Note

This event is equivalent to the DesktopWindow.Deactivated event in a desktop app.


WebPage.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.


WebPage.Overflowed

Overflowed(width As Integer, height As Integer)

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


WebPage.Resized

Resized

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


WebPage.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.Text = "Welcome!"
Else
  Me.Text = "Welcome, " + Session.UserName
End If

Notes

One important difference, of course, is that several pages may be displayed in the same browser window (though not at the same time, of course). But in other respects, a WebPage is very much like a desktop window. In both cases, the state of controls is managed automatically. You will only lose state when you call the Close method of a page or when the application quits. Page state is managed on a per session/per page basis. See the WebSession object. That means two sessions (two users) would each have their own state per page.


Bookmarking

Hash Tags (aka anchors or URL fragments) are used to create bookmarks to specific pages or areas of your web apps. This is an example hash tag:

http://www.example.com/#Hashtag

The WebSession property is used to change a hash tag and WebSession event is used to know when a hash tag has been changed.

For more information on hash tags, refer to the WebSession class.

Compatibility

Web projects on all supported operating systems.

See also

WebView parent class; WebSession, WebDialog, WebContainer and DesktopWindow classes.