To add a shortcut menu to an ASP.

Source: Internet
Author: User

  • ContextMenu Control shortcut menu Controls Overview:

    Several examples of DHTML shortcut menus are included in MSDN liabrary. The method of failure to implement this function is provided separately. A shortcut menu is a set of markup code that is located anywhere in the page. It consists of two parts-the interface and the script (when the user associates the UI when the page is right-clicked), the UI provides a clickable list of elements--menu items--and the respective content text, icon, command name, destination URL, hint (tooltip), And all the things that you think are necessary to show out. The shortcut menu interface is part of the page and belongs to a member of the page control tree. (Too many shortcut menus will appear to perform the problem: ASP, compared to the general situation of most users.) NET will send more shortcut menus to the browser) when the user right-clicks on an element of the page, a piece of JavaScript is raised, and the script moves the shortcut menu to the right-click position.

    The shortcut menu remains hidden, and the shortcut menu is displayed only when the user right-clicks on an element of a binding shortcut menu on the page. The page element receives a script event and pops up a shortcut menu as a response. Script events are trusted by the browser and are oncontexmenu events in Internet Explorer 5.0 and later. In Netscape6.0 and later versions you will use the OnMouseUp event ( You might also use the OnMouseUp event in Internet Explorer 5.0+, but write a few more lines of code) in the script that receives the event, get the UI code block for the shortcut menu and move it to the location where the click occurred. Also set the Visibilty property of the popup panel. When the user clicks on the menu item, the page callbacks and raises the server-side event. For servers, it's no different to click on a menu item and click on a regular button.

    What happens when a user wants to cancel a shortcut menu that has already been opened? In a Windows program, you can cancel a popup shortcut menu by pressing the ESC key or by tapping outside the menu area. So you have to implement this functionality in the Web. Note that the ESC key only has a suburb when the shortcut menu is active (displayed). Because ESC can also be used with other keyboard shortcuts for other elements.

    I can also have the menu hidden when the user moves the mouse over the menu. The onmouseleave event implementation can be manipulated through scripting.

  • using the popup menu control

    Assuming we've designed this popup menu (we'll talk about how to implement the shortcut menu control in a moment), how do you use it to add one or more shortcut menus to an ASP. First, in Visual studio®. NET to drag one or more shortcut menu controls onto the page in the work bar. Then, add menu items for each menu and configure the tooltip, command name, and other required content, such as shortcut keys and links to help topics, for each item. The command name is used to determine which menu item is clicked when responding to a page postback on the shortcut menu, and it must be unique for each shortcut menu control instance's menu item collection.

    You must add code to the OnContextMenu event of the HTML tag to pop up the shortcut menu, and the code must rely on a series of parameters, such as the x, y coordinates of the click, the clicked Element, and the instance of the shortcut menu to use. Note: If necessary, you can use this method to completely replace the browser's shortcut menu. The JavaScript code that is bound to the execution of the OnContextMenu event is dynamically generated at run time. The ContextMenu control exposes a collection property to contain a collection of controls that are bound to the shortcut menu, and the ContextMenu control will give these controls a OnContextMenu property at run time. Ok! finished! can be tested.

    Let's consider the binding mechanism of the Contexmenu control and any element in the page that displays the shortcut menu, how does this mechanism support design time? Ideally, a Contextmenuid property is exposed directly from each of the base class Web controls. Then when you select this property in the Properties window, you will see a list of the ContextMenu controls in the page. Of course these ContextMenu controls we have created, the Contextmenuid property is not supported in ASP. NET 1.x, and is not supported in future asp.net2.0.

    In the visual Studio. NET 2003 integrated development Environment, ASP. NET composite control can do a good job of doing this. You can author new controls by using class composition to compose existing controls. A composite control renders a user interface that re-uses the functionality of an existing control. A composite control can synthesize properties from the properties of a child control and cause the event raised by the child control. It can also expose custom properties and events.

    I don't choose to use composite controls for several reasons: one is that Visual Studio. NET 2003 is not good for extended support for control features in Web Forms (see: Extender Provider components in ASP.NET:an IExtenderProvider implementation), second, the component tray area is no longer supported in Visual Studio 2005 's ASP. The Web Forms Designer now supports only ASP. NET controls and ignores non-visual components such as composite controls. Visual Studio 2005 will no longer trust the InitializeComponent section, and no Tool-generation (tool-generated) code is automatically added to the code file. Asp. NET control is also not designed to have a shortcut menu, so binding a shortcut menu can only be performed by the shortcut menu control itself. Here I use the form of association between an ASP. NET validation control and a validated control.

To add a shortcut menu to an ASP.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.