From Xojo Documentation

Class (inherits from WebToolbarItem)

New in 2011r2

A container control in a WebToolbar.

Badge Container Size
Caption Enabled Tag
Caption Icon Tooltip


An important feature of the WebToolbarContainer is that it enables you to add controls other than buttons and menus to a WebToolbar. Create the container control and add it to the project; then assign it to the Container property of the WebToolbarContainer. The container will be resized to the dimensions of the item. When designing the container, be sure to set all lock properties appropriately.

In order for the container to access the page the toolbar is on, the container must have a property of type WebPage. It can be the actual page, for example WebPage1, or it can be just WebPage. However, if you use WebPage, you will need to typecast in order to get to the actual page. To set up the property, in the Open event of the Toolbar, you will need to cast the toolbar's container control as your original container control. See the example below.

Sample Code

To add a search field to a toolbar, you first create a SearchFieldContainer by adding a WebSearchField to a ContainerControl.

On WebPage1, add a toolbar and then add a Container item to it (named "SearchControl"). Select it and enter "SearchFieldContainer" in the Target property field. You'll also want to change the Size property to 200.

Now run the app to see the SearchField in the toolbar.

Accessing Web Page Information from the Container

Most of the time, the container will need to access the Web Page that contains it.

You can do this in the Open event handler for the toolbar that is on the web page. This code gets the WebToolbarContainer that is named "SearchField" on the toolbar and casts it to a SearchFieldContainer so that the ParentPage property (added to SearchFieldContainer: ParentPage As WebPage1) can be set to the web page (Self):

// Link the SearchField container control to the web page
Var search As WebToolbarContainer
search = WebToolbarContainer(Me.ItemWithName("SearchControl"))

Var searchField As SearchFieldContainer
searchField = SearchFieldContainer(search.Container)
searchField.ParentPage = Self

This can also be written more succinctly like this:

SearchFieldContainer(WebToolbarContainer(Me.ItemWithName("SearchControl")).Container).ParentPage = Self

With ParentPage property value now specified, you can have code on the SearchFieldContainer that uses it to access methods, properties or controls on the web page. This code in the WebSearchField.TextChanged event handler (on the SearchFieldContainer) adds search criteria to a ListBox on the web page when the user presses return/enter in the search field:

If ParentPage Is Nil Then Return // Ensure that ParentPage was configured before using it

If Me.Text <> "" Then
// If the user typed something, then add it to the ListBox on the web page
ParentPage.RecentSearchesList.InsertRow(0, Me.Text)
End If

See Also

WebMenuItem, WebToolbar, WebToolbarButton, WebToolbarFlexibleSpace, WebToolbarItem, WebToolbarMenu, WebToolbarSeparator, WebToolbarSpace classes.