Ticket T324388
Visible to All Users

HtmlEditor - How to add a custom toolbar item

created 9 years ago

Hi,

I have a scenario where I create a custom  Save button that appears below the HtmlEditor:

C#
Html.DevExpress().Button(buttonsettings => { buttonsettings.Text = "Save"; buttonsettings.ClientSideEvents.Click = "function(s, e) { HelpPopupControl.PerformCallback(); }"; }).Render();

This independent button currently looks awkward, so I would like to replace it with a toolbar item; unfortunately, the HtmlEditorToolbarItem does not have a ToolbarSaveButton type.

So I tried ToolbarCustomItem instead like this:

C#
toolbar.Items.Add<ToolbarCustomItem>(btn=> { btn.Text = "Save"; });

This returns the following error: "The type ToolbarCustomItem cannot be used as type parameter 'T' in a generic type or method…"

How to use ToolbarCustomItem and handle ClientSideEvents.Click in this case?

Thank you.

Answers approved by DevExpress Support

created 9 years ago (modified 9 years ago)

Hello,

The ToolbarCustomItem class is a base class for toolbar items and it cannot be added directly to the items collection. Try use one of its descendants instead, for instance, CustomToolbarButton:

C#
toolbar.Items.Add<CustomToolbarButton>(c => { c.CommandName = "save"; c.Text = "Save"; });

To handle this button click, use the ASPxClientHtmlEditor.CustomCommand event. I've attached a sample project to demonstrate this solution.

    Comments (1)

      Thank you Helen. This solved my problem beautifully.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.