Ultimately, a menu system must have actions associated with the menu items to be of any use. C1WebCommand’s menu items allow you to associate one of the following three kinds of actions with them:
· Invoke the form’s postback
· Open a URL
· Arbitrary piece of client-side code
Invoking the Postback Event
To make an item invoke the postback event when the user clicks it, attach an event handler to the item’s ItemClick or ItemSelect event of the menu containing the item. When a menu item is clicked, the form is posted back to the server, and the corresponding event fires for the menu item (if an item has the ItemClick event handler attached, they are fired in sequence). For Command events the item’s CommandName and CommandArgument properties are passed to the event handler. For the ItemClick event, the item clicked by the user is passed to the event handler.
Invoking the ItemClick and ItemSelect Events
The C1WebMenu class has ItemClick and ItemSelect events. The ItemClick event fires when an item is clicked and the ItemSelect event fires when an item is selected. To make an item open in another location when clicked, specify that location’s URL in the item’s NavigateUrl property. When the user clicks such an item, the specified location will be opened in the same window.
Executing Arbitrary Client-Side Script Code
The third option allows you to execute arbitrary client-side script code when the menu item is clicked. To do this, set the value of the item’s ClientScripts property to the string containing the script. That string will be executed as a script when the user clicks the item.
Do not associate more than one action option with a specific item (for example, do not specify both a ClientScripts and a NavigateUrl for the same item). By doing this, it becomes ambiguous as to which action option should take precedence.
Note: In this version of C1WebCommand2, ClientScripts takes precedence over NavigateUrl, and that in turn takes precedence over ItemClick or Command event handlers, but it is not guaranteed that this will hold true in future versions.
It is perfectly valid and in fact can be useful to associate both an action and a submenu with the same item. For example, an item can have the URL of your company’s Web home page specified as the value of its NavigateUrl and have a submenu with URLs of different pages inside your Web site. In that case, clicking the menu item will open the home page, while opening the submenu and clicking an item inside will take the user directly to a specific location within the site.
Send comments about this topic to ComponentOne. Copyright © ComponentOne LLC. All rights reserved. |