Context Menu
- 4 minutes to read
A context menu is a popup menu displayed when a user right-clicks content (text, image, table, etc.) within the editor.
The context menu contains a collection of items (HtmlEditorContextMenuItem objects). To access the collection, use the ASPxHtmlEditor.ContextMenuItems property. The collection is an HtmlEditorContextMenuItemCollection class instance that has methods and properties to access and manipulate (add or delete) menu items.
The ASPxHtmlEditorSettings.AllowContextMenu property allows you to specify the type and availability of the context menu.
AllowContextMenu property value | Corresponding menu type |
---|---|
True | An HTML Editor menu that contains common (Cut, Copy, Paste, and Select All) and context-specific (Modify Table, Change Image, and so on) operations. |
Default | A browser’s context menu (for IE, Chrome, and so on) that contains commands specific to a particular browser. |
False | A context menu is not shown. |
Note
You can invoke a context menu only in the editor’s Design View and HTML View.
Default Context Menu Items
A context menu contains the following items:
Item | Description |
---|---|
Items available in Design view | |
Cut | Cuts the selection to the clipboard. See the note below the table. |
Copy | Copies the selection to the clipboard. See the note below the table. |
Paste | Pastes content from the clipboard to the current cursor position. See the note below the table. |
Select All | Selects all editor content. |
Unlink | Removes the current link element. |
Change Link | Invokes the Change Link dialog for the current link. |
Change Image | Invokes the Change Image dialog for the current image. |
Change Audio | Invokes the Change Audio dialog for the current audio element. |
Change Video | Invokes the Change Video dialog for the current video element. |
Change Flash | Invokes the Change Flash dialog for the current flash element. |
Change YouTube Video | Invokes the Change YouTube Video dialog for the current YouTube video element. |
Change Placeholder | Invokes the Change Placeholder dialog for the current placeholder. |
Table Properties | Invokes the Table Properties dialog for the current table. |
Row Properties | Invokes the Row Properties dialog for the current row. |
Column Properties | Invokes the Column Properties dialog for the current column. |
Cell Properties | Invokes the Cell Properties dialog for the current cell. |
Insert Table | Inserts a new table. |
Insert Row Above | Inserts a table row above the current one. |
Insert Row Below | Inserts a table row below the current one. |
Insert Column to the Left | Inserts a table column to the left of the current one. |
Insert Column to the Right | Inserts a table column to the right of the current one. |
Split Horizontally | Splits the current cell horizontally into two cells. |
Split Vertically | Splits the current cell vertically into two cells. |
Merge Right | Merges the current table cell with the right one. |
Merge Down | Merges the current table cell with the bottom one. |
Delete Table | Deletes the current table. |
Delete Row | Deletes the current table row. |
Delete Column | Deletes the current table column. |
Items available in HTML view | |
Outdent | Decrease an indent for the current paragraph. |
Indent | Increase an indent for the current paragraph. |
Comment | Comments the selected code lines. |
Uncomment | Uncomments the selected code section. |
Format Document | Formats the HTML document. |
Collapse Tag | Collapses the current tag. |
Expand Tag | Expands the current tag. |
Default item visibility is switched based on the currently selected element.
Note
Some browsers (for example, Firefox, Chrome) do not allow scripts to work with the clipboard for security reasons. Therefore, the Cut, Copy, and Paste items are removed from the context menu for these browsers.
Context Menu Runtime Customization
ASPxHtmlEditor allows you to customize default content menu items and create custom items. To modify an item collection, use members of the HtmlEditorContextMenuItemCollection class.
The code sample below demonstrates how you can handle the ASPxClientHtmlEditor.ContextMenuShowing event to change the content of a context menu (by changing its items visibility).
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
MyHtmlEditor.ContextMenuItems.CreateDefaultItems();
MyHtmlEditor.ContextMenuItems.Insert(0, new HtmlEditorContextMenuItem("Add Title...", "AddTitle"));
MyHtmlEditor.ContextMenuItems.Insert(1, new HtmlEditorContextMenuItem("Change Title...", "ChangeTitle"));
MyHtmlEditor.ContextMenuItems.Insert(2, new HtmlEditorContextMenuItem("Remove Title", "RemoveTitle"));
}
}
Note that if you create custom context menu items within ASPxHtmlEditor, default items are not created automatically. To manually populate a context menu with default items, call the HtmlEditorContextMenuItemCollection.CreateDefaultItems method.
Context Menu Design-time Customization
You can customize a context menu item collection at design time using the ASPxHtmlEditor Designer or directly in markup.