How To Modify the Toolbar
AdHoc Toolbar API Toolbar represents set of controls (mainly - buttons), which allow user quick access to most often used features. AdHoc has set of classes that allow to construct any toolbar dynamically using API, but there are four pre-refined (default) toolbars in AdHoc: Report Designer toolbar (Fig. 1a) - the most complex one. Report Viewer toolbar (Fig. 1b) Dashboard Designer toolbar (Fig. 1c) Dashboard Viewer toolbar (Fig. 1d) - the simplest one.
a)  b) c) d) Figure 1. Default AdHoc toolbars. AdHoc allows either customize default toolbars, or create completely new toolbar, by manipulating basic toolbar objects using toolbar API. Toolbar is implemented by class Toolbar, which has collection of ToolbarItem. Any control derived from ToolbarItem represents basic toolbar object and can be placed at the Toolbar. Since ToolbarItem is derived from WebControl, it has all of its' properties and events, like Enabled, Visible, etc. AdHoc has three built-in toolbar controls derived from ToolbarItem:
- ToolbarButton
- ToolbarCheckBox
- ToolbarSeparator
Next we will consider each of them.
ToolbarButton ToolbarButton appears as usual button, can have glyph, text, tip, onclick event. Sample ToolbarButton is presented at Fig. 2.
 Figure 2. Sample button at the toolbar.
ToolbarButton has following properties:- string Text - Text displayed at the button ("Sample" at the Fig. 2).
- string ToolTip - Text of the tooltip shown if mouse is moved over button (see Fig. 3).
 Figure 3. Tooltip near Sample button (mouse cursor is hidden).
- string ImageName - Name of the file with the image (for built-in AdHoc images). At the figure 4 Sample button with ImageName="sql.gif" is presented.
Figure 4. Image at the button.
- string ImageUrl - This property has exactly the same effect as ImageName, but accepts URL to image instead of just its' name.
- string HRef - If set, button acts as link to the URL inside the root directory of the AdHoc site (virtual directory). For example if there is Settings.aspx page with AdHoc Settings in the root directory, then button with URL="Settings.aspx" will redirect user to that Settings.aspx page when clicked.
Also HRef allows to execute JaveScript if "javascript:" is placed at the beginning. For example button with HRef="javascript:alert('Sample');" will show message box with "Sample" text when clicked.
- string Target - Value of the target window property (Similar to '<a href="..." target="_blank"></a>'). Can have following values: _blank, _parent, _self, _top.
- bool AutoPostback - Determines if click on button should initiate postback.
- string ButtonWidth - Defines button width (in pixels) at the toolbar.
- event EventHandler ButtonClick - Server-side handler of click on the button.
ToolbarCheckBox ToolbarCheckBox appears as checkbox integrated into the toolbar. Sample checkbox is presented at figure 5.
 Figure 5. Sample checkbox at the toolbar.
ToolbarCheckBox has following properties:
- string Text - Text displayed near the checkbox ("Sample" at the Fig. 5).
- string ToolTip - Text of the tooltip shown if mouse is moved over checkbox. Similar to same property of button (see Fig. 3).
- bool AutoPostback - Determines if click on button should initiate postback.
- bool Checked - Defines current state (checked or not).
- event EventHandler CheckChange - Server-side handler of checkbox change state.
ToolbarSeparator ToolbarSeparator has no properties, and represents vertical stroke which visually separates groups of different controls at the toolbar (Fig. 6). Figure 6. Toolbar controls separator.
Constructing toolbar All toolbar controls are placed to the toolbar, which is represented by class Toolbar. It has public property ToolbarItemsCollection Items which contains all current controls, and three internal methods:
- void AddItem(ToolbarItem item) - adds control derived from ToolbarItem to the end of toolbar.
- void AddItem(ToolbarItem item, int position) - adds control derived from ToolbarItem to the specified position at the toolbar.
- void RemoveItem(string id) - Searches and removes item with specified id from the toolbar.
Items are shown at the toolbar in the order of their presence in Items collection. Here is sample code that creates button and checkbox with separator between them: Toolbar toolbar; ... ToolbarButton sampleButton = new ToolbarButton(); sampleButton.Text = "MyButton"; toolbar.AddItem(sampleButton); ToolbarSeparator sampleSeparator = new ToolbarSeparator(); toolbar.AddItem(sampleSeparator); ToolbarCheckBox sampleCheckbox = new ToolbarCheckBox("MyCheck", false, false); toolbar.AddItem(sampleCheckbox);
Result of this code is presented at figure 7.
Figure 7. Result of executing sample code adding button and checkbox with separator between them to the toolbar. Constructing toolbar controls You can create your own toolbar controls. The most simple way is to wrap existing controls into the ToolbarItem. See example of such code below for the textbox basing on ASP.NET TextBox control:
using System; using System.ComponentModel; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls;
namespace Izenda.Web.UI { [ToolboxItem(false)] public class ToolbarTextBox : ToolbarItem { HtmlTableCell titleCell = new HtmlTableCell(); HtmlTableCell boxCell = new HtmlTableCell(); private string _value = ""; public string Value { get { return _value; } set { _value = value; } }
protected override void CreateChildControls() { base.CreateChildControls(); Content.Attributes["class"] = "izenda-toolbar"; Content.Style["padding"] = "1px"; Content.Style["border"] = "none"; HtmlTable contentTable = new HtmlTable(); Content.Controls.Add(contentTable); contentTable.CellPadding = 1; contentTable.CellSpacing = 0; contentTable.Border = 0; HtmlTableRow contentRow = new HtmlTableRow(); contentTable.Rows.Add(contentRow); contentRow.Cells.Add(boxCell); boxCell.Attributes["class"] = "izenda-toolbar"; TextBox textBox = new TextBox(); textBox.Text = Value; boxCell.Controls.Add(textBox); contentRow.Cells.Add(titleCell); titleCell.Attributes["class"] = "izenda-toolbar"; titleCell.NoWrap = true; } protected override void OnInit(EventArgs e) { EnsureChildControls(); base.OnInit(e); } } } This class implements simple textbox control for toolbar. Code below demonstrates how it can be used:
ToolbarTextBox sampleItem = new ToolbarTextBox(); sampleItem.Value = "Testing"; toolbar.AddItem(sampleItem);
At the figure 8 you can see textbox created by the code above.
Figure 8. Custom textbox toolbar control.
|
Type: How-To
|