Class

# WebControl

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

The common super class for all web controls that can appear in the browser. It cannot be instantiated or subclassed.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                | Type                                       | Read-Only | Shared |
|-------------------------------------|--------------------------------------------|-----------|--------|
| `ControlID<webcontrol.controlid>`   | `String</api/data_types/string>`           | ✓         |        |
| `Enabled<webcontrol.enabled>`       | `Boolean</api/data_types/boolean>`         |           |        |
| `Name<webcontrol.name>`             | `String</api/data_types/string>`           | ✓         |        |
| `Page<webcontrol.page>`             | `WebPage</api/user_interface/web/webpage>` | ✓         |        |
| `PanelIndex<webcontrol.panelindex>` | `Integer</api/data_types/integer>`         |           |        |
| `Parent<webcontrol.parent>`         | `WebView</api/user_interface/web/webview>` | ✓         |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                              | Parameters                                                                                                                | Returns | Shared |
|---------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|---------|--------|
| `Close<webcontrol.close>`                         |                                                                                                                           |         |        |
| `ExecuteJavaScript<webcontrol.executejavascript>` | script As `String</api/data_types/string>`                                                                                |         |        |
| `GoToURL<webcontrol.gotourl>`                     | url As `String</api/data_types/string>`, inNewWindow As `Boolean</api/data_types/boolean>` = `False</api/language/false>` |         |        |
| `UpdateBrowser<webcontrol.updatebrowser>`         |                                                                                                                           |         |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                          | Parameters | Returns |
|-------------------------------|------------|---------|
| `Closed<webcontrol.closed>`   |            |         |
| `Opening<webcontrol.opening>` |            |         |

## Property descriptions

<div id="webcontrol.controlid">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebControl.ControlID

**ControlID** As `String</api/data_types/string>`

> Identifies the control on a per session basis.
>
> This property is read-only.

<div id="webcontrol.enabled">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebControl.Enabled

**Enabled** As `Boolean</api/data_types/boolean>`

> When `True</api/language/true>` the <span class="title-ref">WebControl</span> is drawn enabled and responds to user action. When `False</api/language/false>`, the control appears as disabled and does not respond to user actions.
>
> In the case of `WebTimer</api/web/webtimer>`, when set to `False</api/language/false>` this disables and stops the WebTimer. When set to `True</api/language/true>`, it starts the WebTimer.
>
> Disable a button when a check box value changes:
>
> ``` xojo
> If AllowSaveCheckBox.Value Then
>   SaveButton.Enabled = True
> Else
>   AllowSaveButton.Enabled = False
> End If
> ```

<div id="webcontrol.name">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebControl.Name

**Name** As `String</api/data_types/string>`

> The name of the control.
>
> This property is read-only.

<div id="webcontrol.page">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebControl.Page

**Page** As `WebPage</api/user_interface/web/webpage>`

> Identifies the web page that contains the control.
>
> This property is read-only.

<div id="webcontrol.panelindex">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebControl.PanelIndex

**PanelIndex** As `Integer</api/data_types/integer>`

> If the control has been placed on a <span class="title-ref">WebTabPanel</span> or `WebPagePanel</api/user_interface/web/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 <span class="title-ref">WebTabPanel</span> or `WebPagePanel</api/user_interface/web/webpagepanel>` control, it returns the panel number. If the control is not on a `WebPagePanel</api/user_interface/web/webpagepanel>` or <span class="title-ref">WebTabPanel</span>, 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<webpagecontrol.selectedpanelindex>`.
>
> This code displays the panel index of the control that is on the page.
>
> ``` xojo
> MessageBox(Me.SelectedPanelIndex.ToString)
> ```

<div id="webcontrol.parent">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebControl.Parent

**Parent** As `WebView</api/user_interface/web/webview>`

> Used to get the control's parent control or page. If the parent control is a `WebContainer</api/user_interface/web/webcontainer>`, then it returns the `WebContainer</api/user_interface/web/webcontainer>`. If it is on a `WebPage</api/user_interface/web/webpage>`, it returns the `WebPage</api/user_interface/web/webpage>`.
>
> This property is read-only.

## Method descriptions

<div id="webcontrol.close">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebControl.Close

**Close**

> Removes the control from the page.

<div id="webcontrol.executejavascript">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebControl.ExecuteJavaScript

**ExecuteJavaScript**(script As `String</api/data_types/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](https://www.ecma-international.org/ecma-262/6.0/).
>
> This code in the Pressed event of a Button displays an alert using JavaScript:
>
> ``` xojo
> Me.ExecuteJavaScript("alert('Hello!');")
> ```
>
> This code will select the text in a WebTextField (or WebTextArea):
>
> ``` xojo
> WebTextField1.ExecuteJavascript("document.getElementById('" + _
> WebTextField1.ControlID + "_inner').select();")
> ```

<div id="webcontrol.gotourl">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebControl.GoToURL

**GoToURL**(url As `String</api/data_types/string>`, inNewWindow As `Boolean</api/data_types/boolean>` = `False</api/language/false>`)

> Opens the passed *url* in place of the current web page or downloads a file. If *inNewWindow* is `True</api/language/true>`, the browser is asked to open the *url* in a new window.
>
> If the browser has popup windows disabled and *inNewWindow* is `True</api/language/true>`, the method silently fails and the page is not shown.
>
> If *inNewWindow* is `False</api/language/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</api/user_interface/web/webhtmlviewer>` control.
>
> Display a web site in a new popup window:
>
> ``` xojo
> Me.GoToURL("http://www.wikipedia.org", True)
> ```

<div id="webcontrol.updatebrowser">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebControl.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</api/databases/rowset>` of `database rows</api/databases/databaserow>`, updates a `ProgressBar</api/user_interface/web/webprogressbar>` and then forces the updated `ProgressBar</api/user_interface/web/webprogressbar>` to be sent to the browser via UpdateBrowser.
>
> ``` xojo
> ProgressBar1.MaximumValue = SalesData.RowCount
> For Each row As DatabaseRow in SalesData
>   AnalyzeSales(row)
>   ProgressBar1.Value = ProgressBar1.Value + 1
>   ProgressBar1.UpdateBrowser
> Next
> ```

## Event descriptions

<div id="webcontrol.closed">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebControl.Closed

**Closed**

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

<div id="webcontrol.opening">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebControl.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<webuicontrol.shown>` event to initialize controls.

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | Web |
| **Operating Systems** | All |

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `WebDialog</api/user_interface/web/webdialog>`, `WebPage</api/user_interface/web/webpage>` classes

</div>
