



A toolbar control may contain multiple ToolbarItem objects. A ToolbarItem can be one of these types:
To add an item to your toolbar, follow the steps below:
Members
Properties
The following table provides a list of properties and events of
interest. For complete reference information, see the Toolbar
control in the library reference section.
| Property Name | Type | Description |
|---|---|---|
| Alignment | Alignment | Alignment of the text and image on a Command or Tool. |
| BuddyControls | BuddyControlCollection | A set of PageLayout or Map controls that this Toolbar acts on. |
| BuddyControlType | BuddyControlType | The type of the buddy controls associated with this control. Either a set of Map controls or a set of PageLayout controls can be associated with this control, but not a set of both. |
| CurrentTool | string | The selected Tool on this Toolbar. There can only be one CurrentTool among a group of Toolbar controls. |
| Group | string | The group to which this Toolbar belongs. A group of Toolbar controls can have only one CurrentTool among them. The Group property cannot be set to null or or to an empty string. |
| Orientation | Orientation | The orientation of the Toolbar: horizontal or vertical. |
| TextPosition | TextPosition | Position of the text with reference to the image on a Command or Tool. Applies only to toolbars with the ImageAndText ToolbarStyle. |
| ToolbarItemDefaultStyle | Style | The style applied to Commands and Tools when they are not selected, disabled, or hovered upon. |
| ToolbarItemDisabledStyle | Style | The style applied to Commands and Tools when they are disabled. |
| ToolbarItemHoverStyle | Style | The style applied to Commands and Tools when they are hovered upon. |
| ToolbarItems | ToolbarItemCollection | The collection of ToolbarItem objects on this Toolbar. The Tools defined here will override the ToolItems on the Map or PageLayout controls that you set up as this Toolbar's buddy controls. |
| ToolbarItemSelectedStyle | Style | The style applied to Commands and Tools when they are selected. |
| ToolbarStyle | ToolbarStyle | The style of the toolbar: whether it displays both text and image for a command or tool, or only one of the two. |
Events
| Event Type | Description |
|---|---|
| CommandClick | Raised when a command on the Toolbar has been clicked. An viable option for handling all commands in one location. |
| DropDownBoxIndexChange | Raised when the selected index of a select item on the Toolbar has changed. Only fired if AutoPostBack is True on the select item. |
As a Web application developer, you will likely need to manage end user interaction with Web ADF controls in your application. In most cases, a user will need to interact with a Map control, which involves some action on the client and some action on the server. The client-side action is what allows you to, for example, draw a box over the control. The server-side action is what allows you to use the coordinates of the box and, for example, zoom in. During every interaction with the Map, two things happen:
When you add your own items to a toolbar, you need to set their properties to specify what will happen on the client and the server when that item is selected. The form you use to add items to your toolbar is the ToolbarCollectionEditorForm. In this dialog, click the button below the Show Properties label to expand the form and show the properties of individual tools and commands. In particular, you will be concerned with setting the properties associated with the tool or command’s client and server-side actions. The following section contains more detailed information about how to configure custom tools and commands on a toolbar. For an example of adding custom tools and commands to a toolbar.
A Tool requires the user to perform a client-side action by interacting with a map or page layout control. Once the user completes the client action, a server-side action executes on the control. For example, to use a Zoom In tool, the user initiates a client action by drawing a box on a map or page layout control. Once the user finishes drawing the box, a server action executes and the view extent changes.
Client-side actions are controlled by JavaScript functions that execute on the client, prior to any requests being sent to the server. The Web ADF includes prewritten JavaScript code for common interactions such as drawing a box. The map and page layout controls each have their own JavaScript functions.
Use the tool’s ClientAction property to specify the client action. With
this property, you’ll see the list of prewritten JavaScript functions and also
a custom option that allows you to write your own function. Choosing the
custom JavaScript option displays a dialog box into which you can enter your
JavaScript code. You might simply call your own JavaScript function before
calling one of the prewritten JavaScript functions.
Each ClientAction is associated with a JavaScript function that sets
the tool mode for interaction with a Map or PageLayout. In general, the name of
the JavaScript function is the toolbar buddy type, Map or Page (PageLayout),
plus the ClientAction. For example, a ClientAction
of DragRectangle is associated with the MapDragRectangle JavaScript function
(in display_map.js). The table below provides a comprehensive review of
the association between out-of-the-box ClientAction settings and
the Web ADF JavaScript function called when initializing (clicking
on) a tool.
| ClientAction | Web ADF JavaScript function | |
|---|---|---|
| Map | PageLayout | |
| Point |
MapPoint |
PagePoint |
| Line |
MapLine |
Not applicable |
| Polyline |
MapPolyline |
Not applicable |
| Polygon |
MapPolygon |
Not applicable |
| DragRectangle | MapDragRectangle | PageDragRectangle |
| DragImage | MapDragImage | PageDragImage |
| Circle | MapCircle | Not applicable |
| Oval | MapOval | Not applicable |
| MapDragImage | Not applicable | PageMapDragImage |
| MapDragRectangle | Not applicable | PageMapDragRectangle |
| MapPoint | Not applicable | PageMapPoint |
MapDragRectangle('Map1', '%toolbarItem%', false, 'hand');
The parameters are map id, toolbar item id, show a loading icon, and cursor
type. The show loading icon is not currently implemented and thus not used. In
the custom JavaScript dialog, a convenience variable for the id of the toolbar
and toolbar item can be defined as %toolbar% and %toolbarItem%,
respectively.
var dragboxdiv = document.getElementById('DragBoxDiv');
dragboxdiv.style.borderColor = 'red';
dragboxdiv.style.borderWidth = '10px';
dragboxdiv.style.filter = 'alpha(opacity=100)';
dragboxdiv.style.backgroundColor = '';
MapDragRectangle('Map1', '%toolbarItem%', true, 'hand');
Note, in this example the id ‘DragBoxDiv’ is specified in the DragBoxObject
function in display_common.js. On initial load of the Map, a
set of JavaScript code is written to the page that calls the DragBoxObject
function to create a div with the id “DragBoxDiv”. The div maintains
properties (i.e. color, size, opacity) of the “dragbox”.In a more complex scenario, you might handle all of the client interaction with your custom JavaScript. In this case, your custom ClientAction JavaScript should set up a function that is called at the onmousedown event of an HTML element on the form. You would use the JavaScriptFile property to embed the JavaScripts required for your custom ClientAction into the page itself.
The ServerAction method for a Tool has a single argument of type
ToolEventArgs. The ClientAction property for the Tool (set at design-time
in the Toolbar Item Collection Editor), defines how a user will
use the tool to interact with the Map, which Web ADF JavaScript
functions will process the interaction, and the type of information contained
by the ToolEventArgs. The client-side interaction (JavaScript) is handled
for you. The server-side implementation must be customized and usually
involves working with user provided information via the
ToolEventArgs. ToolEventArgs contains the geometry generated
by a user interacting with the Map. The type of ClientAction will
dictate the type of geometry. For example, if the ClientAction property
is set to Point, the ToolEventArgs parameter must be cast to PointEventArgs to
access the user-defined point. Note that the geometry returned is always
in screen units. The table below links a Tool's ClientAction
property with the type of ToolEventArgs you can cast to in your custom tool
implementation.
| ClientAction | ToolEventArgs type |
|---|---|
| Point |
PointEventArgs |
| Line |
LineEventArgs |
| Polyline |
VectorEventArgs, PolylineEventArgs |
| Polygon |
VectorEventArgs, PolygonEventArgs |
| DragRectangle | RectangleEventArgs |
| Circle | CircleEventArgs |
| Oval | OvalEventArgs |
A tool’s server-side action executes after the client-side JavaScript has posted back to the buddy control or toolbar control. You must provide a server-side action for each tool you add to a toolbar. The ESRI.ArcGIS.Server.WebControls.Tools namespace includes a few common server-side actions for tools, such as Zoom In, Zoom Out, and Pan. For extended functionality, you can write your own classes to handle server-side actions.
Two properties work together to indicate the location of a tool’s server-side code: ServerActionAssembly and ServerActionClass. They indicate the assembly and class which contain the server-side code that your tool will execute. Both of these properties must be satisfied unless you are writing server-side code based on events.
ServerActionAssembly is the fully qualified display name of the assembly containing the code for the server-side action. This could be the name of a class library that you added to a Visual Studio Solution, or, if you simply added a class to your current project, it is the name of your current project. If you added the code within the App_Code directory of your website, the ServerActionAssembly is App_Code.
ServerActionClass is the fully qualified name of the class that contains the server-side action code. Once you enter a valid ServerActionAssembly name, all of the available classes in the assembly become available in the ServerActionClass dropdown list. You must then select a class from this list. You can also manually enter the fully qualified class name. If the class is in a namespace, the format will be: <namespace>.<classname>
A class that contains server-side tool code needs to implement a tool action interface. For toolbars with BuddyControlType set to Map, the class must implement IMapServerToolAction; for toolbars with BuddyControlType set to PageLayout, the class must implement IPageServerToolAction. These interfaces each contain one method— ServerAction—which is automatically stubbed out for you when you implement the interface. This is where you write the tool’s server-side code.
Points to remember when adding your own class:
A command requires no user interaction; it executes immediately when clicked. A command can have a client action, a server action, or both. You set a command’s client and server actions in much the same way explained above for tools; however, a command coded in a class needs to implement a command action interface instead of a tool action interface. These are IMapServerCommandAction and IPageServerCommandAction, depending on the buddy control type of the toolbar that contains the command.
If you prefer to write the server-side code for your commands directly in the
page, you can use the toolbar control’s CommandClick event. The argument passed
into the event handler is of type ToolbarCommandClickEventArgs. This argument
has a property called CommandName through which you can find out which command
an end user clicked. You can use a switch or Select Case statement based on
CommandName to execute the appropriate server-side action based on the command
clicked.
Toolbar control
The Toolbar control provide a prepackaged framework for adding
client-side tools to interact with Web ADF controls.
The callback framework is managed for you. You only need to create a
class on the server that implements the appropriate interface (depending on the
type of toolbar item) and add that class to the
Toolbar. Implementation code in the toolbar item class can interact
and change any server-side resource and the callback response is managed for
you. This is the easiest way to tap into the Web ADF callback
framework, but requires you to work within the Toolbar framework.
The table below lists the toolbar item types and interface to
implement:
| Toolbar Item | Interface | Description |
|---|---|---|
| Tool |
IMapServerToolAction |
Requires user to activate then initiate server-side action by interacting with a Map control |
| Command |
IMapServerCommandAction |
User initiates server-side action on click |
| DropDownBox |
IMapServerDropDownBoxAction |
Requires user to select item to initiate server-side action |
All toolbar item interfaces define a ServerAction method, but different
argument types. The ServerAction method for Command and DropDownBox
items has a single argument of type ToolbarItemInfo. For a tool it is
always a type of ToolEventArgs. Here is an example of how they may be
used in code:
public class CustomTool : IMapServerToolAction {
public void ServerAction(ToolEventArgs args)
{
Map map = (Map)args.Control;
PointEventArgs pea = (PointEventArgs)args;
}
}
public class CustomCommand : IMapServerCommandAction {
public void ServerAction(ToolbarItemInfo info) {
Map map = (Map)info.BuddyControls[0];
}
}
public class CustomDropDownBox : IMapServerDropDownBoxAction {
public void ServerAction(ToolbarItemInfo info) {
DropDownBox dropDownBox = (DropDownBox)info.Toolbar.ToolbarItems.Find("DropDownBoxId");
string dropDownBoxValue = dropDownBox.SelectedValue;
}
}
The custom tool illustrates an example of how to retreive the buddy control of
the toolbar and cast the ToolEventArgs to the appropriate type, depending on
the client action (see table in the Configuring custom tools section
above). Both the custom command and drop down box illustrate how
to retrieve the buddy control of the toolbar. You can also get a
reference to the drop down list and retrieve the value selected.
The toolbar itself has a CommandClick event that can be handled to include
all command related code in a single event method. Here is an
example of how the event handler method may be used to work with multiple
commands in a toolbar. Note, you do not need to create a custom class and
implement the IMapServerCommandAction interface to create a custom
command. As a result, executing server-side code via
a command in a toolbar is much simpler.
protected void Toolbar1_CommandClick(object sender, ToolbarCommandClickEventArgs args)
{
switch (args.CommandName)
{
case ("CustomCommand1"):
{
// do something
break;
}
case ("CustomCommand2"):
{
// do something
break;
}
}
}