|
|||||||||||||||||||||||||
|
|||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
Horizontal Toolbar in Mozilla. The selected item displays a rollover image. Contents
Introduction
A working online demo of the component is available here. Building Toolbars in the designerTo create a Toolbar, no coding is required. If you have added the control to your IDE's toolbox, just drag it on your webform. As there is nothing to preview yet, it will display a grey rectangle:
All the control's properties are accessible via the Toolbar section of the property grid. They are pretty self-explanatory:
To add items to the toolbar, simply click on the button of the
Setting up Toolbar and Toolbar items is pretty straightforward as you get a proper preview of the Toolbar at design time. So the best way to get to know the component is to play around with the different settings, in your IDE...
Toolbar ItemsThe Toolbar comes with built-in support for various item types. Furthermore, arbitrary controls can be plugged into the Toolbar by using an empty container item. (BTW - you can also use the items without a Toolbar. If you just need a single image button with rollovers on your page - just drag the control directly on your web form and you're done.) ToolbarImageThis item renders a simple image with optional rollovers. An additional ToolbarButtonThis item renders an image button which posts back to the server and raises an An additional label ( ToolbarLinkThis item renders a hyperlinked image. Like the ToolbarTextBoxThis item renders an ASP.NET ToolbarLabelRenders a simple text, enclosed in HTML ToolbarSeparatorRenders a separator item. Separators are very simple controls which are configured via the Toolbar's properties. This enables you to conveniently configure all your Toolbar's separators at once. If you want to separate your items with more flexibility, just use ControlContainerItemThis class is an empty container for arbitrary controls. This enables you to plug arbitrary controls into the toolbar at runtime. Say you want to add an ASP.NET
private void Page_Load(object sender, System.EventArgs e) { //get the container item ToolbarItem item = this.Toolbar1.Items["DropdownItem"]; //add the dropdown to the container's Controls collection item.Controls.Add(this.MyDropDownList); } The sample project contains a web form (containeritem.aspx) which adds a Using the codePostBack event handlingYou can register event handlers for toolbar items that post back through the Toolbar's A typical event handler looks like this: /// <summary> /// Handles the toolbar's button events. /// </summary> /// <param name="item">Clicked toolbar button.</param> private void Toolbar1_ItemPostBack(ToolbarItem item) { if (item.ItemId == "SAVE") { //save something } else if (item.ItemId == "DELETE") { //delete something } } Processing Toolbar items at runtimeYou can easily customize your Toolbar at runtime. The Toolbar's As an example: the Edit button of the sample project is being created at runtime. In the code below, a new /// <summary> /// Creates an additional toolbar button and adds it to /// the toolbar's <c>Items</c> collection. /// </summary> private void CreateEditButton() { //create an "edit" button ToolbarButton editItem = new ToolbarButton(); editItem.ID = "EditItem"; editItem.ImageUrl = "images/edit.gif"; editItem.RollOverImageUrl = "images/edit_ro.gif"; editItem.ItemId = "Edit"; editItem.ToolTip = "Click to enable save button"; editItem.ItemCellWidth = Unit.Pixel(100); //get the index of the save button and insert the //edit button right after this one int index = this.Toolbar1.Items.IndexOf("Save"); this.Toolbar1.Items.Insert(index + 1, editItem); } Note that dynamically created toolbar item controls are not being stored in ViewState, so you will have to recreate them on postback! TroubleshootingRollovers don't workThe rollover JavaScript uses the <img src="save.gif" id="saveitem" />
However, this attribute is only available if the If you configure your Toolbar in the designer, IDs are automatically generated. However, if you add your items at runtime through code, you need to specify an ID yourself: //create an "edit" button
ToolbarButton editItem = new ToolbarButton();
editItem.ID = "EditItem";
General formatting troubles with Non-IE browsersPer default, ASP.NET renders down-level output for all non-IE browsers (pathetic...) which prevents the rendering of CSS styles for the Toolbar. As an example, your toolbar could look bad if you use labels for image items:
To properly identify Firefox & Co., it's important to have an updated browserCaps configuration (stands for "Brower Capabilities"). Rob Everhardt did a great job here. You can find an introduction to browserCaps, links and downloads at his site. If you can't update your browserCaps for some reason, you can also fix the Toolbar layout with a declaration in an external stylesheet (the sample assumes the CSS class of the Toolbar is /* adjust images and image buttons via external CSS */
.mytoolbar img, .mytoolbar input
{
vertical-align:middle;
border: none;
}
The sample looks like crap on Netscape 4.xYes, it does, and I can perfectly live with that. I had to choose between deprecated HTML tags ( However, if you need a down-level version of this control, you should be able to get it with very little effort (but don't expect me to do it for you ;-). Have a look at the rendering methods of the Acknowledgements and LicensingTo output JavaScript for the rollover links, I started with a procedure from MetaBuilders' RollOverLink which I adapted to my needs. MetaBuilders offer a nice variety of controls on their site - check it out. The background theme of the horizontal Toolbar sample was taken from the great PHPBB2 bulletin board. Graphics of the vertical Toolbar example are mine, feel free to use them. This control is released under the less restrictive GNU Lesser General Public License (LGPL). While you can't slap your name on it and claim it to be yours (or even sell it), you are free to adapt it to your needs and use it in both free and commercial applications. Have fun! NewsletterThis is the first release and I'm pretty sure there will be bug fixes and enhancements. If you don't want to check back for updates, you can subscribe to a newsletter at my site. History
|
||||||||||||||||||||||||