Cutting Edge: Add to the shortcut menu for the ASP.NET control (2) English Original:
Add a context menu to asp.net controls
Author: Dino Esposito
translation:
Masterlrc
Source code:
CuttingEdge0502.exe
Programming Interface Our ContextMenu control inherits and executes inamingcontainer interface from WebControl
Public Class ContextMenu: WebControl, InamingContainer
Figure 1 control of the member details, as follows:
Property Description AutoHide flag When the user mouse removes the control area, if the shortcut menu BoundControls returns the control collection of the shortcut menu, collect cellpadding returns or sets the spatial number of spaces around each menu item. ContextMenuitems Return to menu items Return to menu items Return or Set When the color method of the mouse is highlighting the menu item Description getScreference Returns the JavaScript code for the shortcut menu in the hidden page when the user presses the ESC button, and this code will be associated with the HTML corresponding to the shortcut menu. Elements. GetonClickReference returns the code that hides the shortcut menu when the user clicks outside the menu area. Event Description Itemmand When the user clicks on a shortcut menu entry. The key attribute is the ContextMenuitmes collection property that contains the object collection of the ContextMenuItem type, and each object represents a menu item. ContextMenuItem class source code as follows: [TypeConverter (typeof (ExpandableObjectConverter))] public class ContextMenuItem {public ContextMenuItem () {} public ContextMenuItem (string text, string commandName) {_text = text; _commandName = commandName;} private string _text; private string _commandName; private string _tooltip; public string Text {get {return _text;} set {_text = value;}} public string CommandName {get {return _commandName;} set {_commandName = value;}} public String Tooltip {get {return _tooltip } set {_tooltip = value;}}} Each menu item has a display text, a command name, a Tooltip. You can extend this class through each method, such as adding a picture URL, an unavailable state, or a target URL, etc. The display text is displayed on the menu item; the command name is a unique identifier string that is used to specify or determine the command associated with the menu item. Tooltip Gets or Sets the tooltip text when the mouse pointer is in the menu item, when the user clicks on the menu item, the page comes back and excited a server-side Itemmand event. The control page performs some code by operating this event to respond to the user's click. Figure 3 is a screenshot of an example of a shortcut menu: To use a shortcut menu, you need to use the Menu Item object to populate the contextMenuItems collection, adjust some visual style, at least one control to the BoundControls collection. Then open the sample page in the browser, right-click on the control of any binding shortcut menu. The effect is as follows: Each menu item contains a LinkButton control, which has an internal binding click event handler. When you detect a click, the page is post-passing and stimulating this click event. The predefined handler then bubbles the event to the previous level and is renamed it is ItemMand. Controls also define some visual properties, like Cellpadding, RolloverColor, and AutoHide. Reiterate, the shortcut menu in Windows can be canceled when the ESC key is pressed or clicked outside the menu area.
For web-based shortcut menu, the AutoHide property adds an ONMOUSELEAVE script for the root label of the shortcut menu, so when the user's mouse leaves the menu area, the subtree of the root label will hide. Take AutoHide as a setable properties, users can automatically hide the shortcut menu when the mouse is left at need. To enable the menu to hide if you click or press the ESC button, you need to add the following handler: