Class
WebButton
Description
The standard button used for web apps.
Properties
Name |
Type |
Read-Only |
Shared |
---|---|---|---|
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
Methods
Name |
Parameters |
Returns |
Shared |
---|---|---|---|
dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All |
|||
dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All |
|||
dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All |
|||
dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All |
|||
dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All |
|||
dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All |
|||
script As String |
|||
Events
Name |
Parameters |
Returns |
---|---|---|
hitItem As WebMenuItem |
||
obj As WebDragItem, action As WebDragItem.DragActionTypes, x As Integer, y As Integer |
||
item As WebMenuItem |
||
Property descriptions
WebButton.AllowAutoDisable
AllowAutoDisable As Boolean
WebButton.Cancel
Cancel As Boolean
If True, the Escape key and Command/Control-Period key sequence trigger the Pressed event.
The Cancel property can only be set to True for a single button each per page at any given moment.
When Cancel is True, the Indicator property is ignored as Cancel buttons have a default indicator.
This example makes the WebButton a cancel button. It is in the Opening event of the control.
Me.Cancel = True
WebButton.Caption
Caption As String
Gets or sets the text of the button.
Buttons can only have a single-line caption.
This code in the Pressed event handler changes the text of the button each time it is pressed:
If Me.Caption = "Blue" Then Me.Caption = "Red" Else Me.Caption = "Blue" End If
WebButton.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 = menuThe 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
WebButton.ControlID
ControlID As String
Identifies the control on a per session basis.
This property is read-only.
WebButton.Default
Default As Boolean
If True, the default button indicator is added to the button and the Return and Enter keys will trigger the Pressed event.
Because there can logically only be one default button per page, only the first WebButton on a page with the Default property set to True will be honored.
When Default is True, the Indicator property is ignored as Default buttons have a default indicator.
This code sets the WebButton as the default button. It is in the Opening event of the control.
Me.Default = True
WebButton.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 Fa:doc:False</api/language/false>`lse this disables and stops the WebTimer. When set to :doc:`True</api/language/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
WebButton.Height
Height As Integer
The height (in pixels) of the control.
WebButton.Indicator
Indicator As Indicators
WebButton.Left
Left As Integer
The position of the left side of the WebUIControl in pixels, relative to the web page.
WebButton.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.
WebButton.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).
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.
WebButton.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.
WebButton.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.
WebButton.LockTop
LockTop As Boolean
Determines whether the top edge of the control should stay at a set distance from the top edge of the parent control, if there is one, or the owning web page.
WebButton.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.
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.
WebButton.Menu
Menu As WebMenuItem
The Menu associated with this button. When a menu is associated with the button, it appears in a section separate from the rest of the button which includes an indicator that a menu is available.
Selecting an item from the menu will cause the MenuSelected event to execute.
This code (in the control's Opening event) adds a menu to the button:
Var theMenu As New WebMenuItem theMenu.AddMenuItem("Yes") theMenu.AddMenuItem("No") theMenu.AddMenuItem("Maybe") Me.Menu = theMenu
WebButton.Name
Name As String
The name of the control.
This property is read-only.
WebButton.PanelIndex
PanelIndex As Integer
If the control has been placed on a WebTabPanel or WebPagePanel control, this is the panel (page/tab) that the control is on. If the control is not on a panel, it returns -1.
The first panel is numbered zero. If the control has been placed on a panel of a WebTabPanel or WebPagePanel control, it returns the panel number. If the control is not on a WebPagePanel or WebTabPanel, it returns -1. If you change the PanelIndex to a nonexistent panel, the control will disappear until you give it a PanelIndex value that corresponds to a panel that exists.
If you are looking to change the currently selected panel (page/tab), use SelectedPanelIndex.
This code displays the panel index of the control that is on the page.
MessageBox(Me.SelectedPanelIndex.ToString)
WebButton.Outlined
Outlined As Boolean
If True the button will appear in outlined style.
WebButton.Page
Page As WebPage
Identifies the web page that contains the control.
This property is read-only.
WebButton.Parent
Parent As WebView
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.
WebButton.TabIndex
TabIndex As Integer
The WebButton'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
WebButton.Tooltip
Tooltip As WebToolTip
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"
WebButton.Top
Top As Integer
The top of the control in local coordinates relative to the web page.
WebButton.Visible
Visible As Boolean
WebButton.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
WebButton.AcceptPictureDrop
AcceptPictureDrop(dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All)
Allows the control to accept a picture drop of a WebDragItem.
WebButton.AcceptRawDataDrop
AcceptRawDataDrop(dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All)
Allows the control to accept a raw data drop of a WebDragItem.
WebButton.AcceptTextDrop
AcceptTextDrop(dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All)
Allows the control to accept a picture drop of a WebDragItem.
WebButton.AllowPictureDrag
AllowPictureDrag(dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All)
Allows the control to be dragged as a picture.
WebButton.AllowRawDataDrag
AllowRawDataDrag(dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All)
Allows the control to be dragged as raw data.
WebButton.AllowTextDrag
AllowTextDrag(dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All)
Allows the control to be dragged as text.
WebButton.Close
Close
Removes the control from the page.
WebButton.CSSClasses
CSSClasses
Returns the instance of WebCSSClasses for this control allowing you to add CSS classes to and remove CSS classes from the control.
WebButton.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();")
WebButton.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)
WebButton.Press
Press
Causes the button's Pressed event to execute.
WebButton.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
WebButton.Style
Style As WebStyle
Returns the WebStyle for the control.
Style(Assigns style As WebStyle)
Assigns the style to the control.
In this example, in any event of the control, set the text to bold:
Var style As New WebStyle style.Bold = True Me.Style = style
WebButton.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.MaximumValue = SalesData.RowCount For Each row As DatabaseRow in SalesData AnalyzeSales(row) ProgressBar1.Value = ProgressBar1.Value + 1 ProgressBar1.UpdateBrowser Next
Event descriptions
WebButton.Closed
Closed
The control has been removed from the browser either because the page has closed or the control's Close method was called.
WebButton.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 = menuThe 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
WebButton.DropObject
DropObject(obj As WebDragItem, action As WebDragItem.DragActionTypes, x As Integer, y As Integer)
Called when a dragged item is over a control that can accept it. The dragged item is contained in obj and the type of drag is identified by action.
WebButton.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.
WebButton.MenuSelected
MenuSelected(item As WebMenuItem)
The WebMenuItem passed was selected from the WebButton's menu.
WebButton.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.
WebButton.Pressed
Pressed
WebButton.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
When the button is pressed or the Press method is called, the Pressed event is called.
The Default and Cancel properties can only be set to True for a single button each per page at any given moment. When either of these properties is True, the Indicator property is ignored as Default and Cancel buttons have a default indicator.
Sample code
This code changes the Caption of a button between Start/Stop when you click it:
If Button1.Caption = "Start" Then
Button1.Caption = "Stop"
Else
Button1.Caption = "Start"
End If
Compatibility
Project Types |
Web |
Operating Systems |
All |
See also
WebUIControl parent class; WebSegmentedButton, WebToolbar classes