Back to Devexpress

ASPxHtmlEditor.ContextMenuItems Property

aspnet-devexpress-dot-web-dot-aspxhtmleditor-dot-aspxhtmleditor-f2a3f824.md

latest3.7 KB
Original Source

ASPxHtmlEditor.ContextMenuItems Property

Gets the collection of items displayed within the editor’s context menu.

Namespace : DevExpress.Web.ASPxHtmlEditor

Assembly : DevExpress.Web.ASPxHtmlEditor.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public HtmlEditorContextMenuItemCollection ContextMenuItems { get; }
vb
Public ReadOnly Property ContextMenuItems As HtmlEditorContextMenuItemCollection

Property Value

TypeDescription
HtmlEditorContextMenuItemCollection

An HtmlEditorContextMenuItemCollection object that is the collection of the context menu items.

|

Remarks

Use the ContextMenuItems property to access a collection of context menu items within the ASPxHtmlEditor. The collection provides methods and properties that allow you to add new items and remove existing ones, access individual items, etc. For more information on items, see the Context Menu topic.

Example

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).

csharp
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"));
     }
}
javascript
function OnContextMenuShowing(s, e) {
     var contextMenu = s.GetContextMenu();
     var selectedElement = myHtmlEditor.GetSelection().GetSelectedElement();
     var isImageSelected = selectedElement && selectedElement.tagName.toLowerCase() == "img";

     SetContextMenuItemVisible(contextMenu, "AddTitle", isImageSelected && !selectedElement.title);
     SetContextMenuItemVisible(contextMenu, "ChangeTitle", isImageSelected && selectedElement.title);
     SetContextMenuItemVisible(contextMenu, "RemoveTitle", isImageSelected && selectedElement.title);
}

function SetContextMenuItemVisible(contextMenu, itemName, visible) {
     var item = contextMenu.GetItemByName(itemName);
     if(item)
          item.SetVisible(visible);
}
aspx
<dx:ASPxHtmlEditor ID="DemoHtmlEditor" runat="server" ClientInstanceName="myHtmlEditor">
     <ClientSideEvents ContextMenuShowing="OnContextMenuShowing"

     ...

</dx:ASPxHtmlEditor>

See Also

HTML Editor

ASPxHtmlEditor Class

ASPxHtmlEditor Members

DevExpress.Web.ASPxHtmlEditor Namespace