Back to Devexpress

ASPxClientHtmlEditor.CustomCommand Event

aspnet-js-aspxclienthtmleditor-4d861299.md

latest6.0 KB
Original Source

ASPxClientHtmlEditor.CustomCommand Event

Enables you to implement a custom command’s logic.

Declaration

ts
CustomCommand: ASPxClientEvent<ASPxClientHtmlEditorCommandEventHandler<ASPxClientHtmlEditor>>

Event Data

The CustomCommand event's data class is ASPxClientHtmlEditorCommandEventArgs. The following properties provide information specific to this event:

PropertyDescription
commandNameGets the name of the processed command.
parameterGets an optional parameter that complements the processed command.

Remarks

The CustomCommand event occurs on the client side when executing a command whose name (returned by the ASPxClientHtmlEditorCommandEventArgs.commandName property) doesn’t coincide with any default command names listed by the ASPxClientCommandConsts object’s constants.

Handle the CustomCommand event to implement the required logic for the executed custom command. You can, for instance, manually execute a set of default commands by handling this event.

Example

The example below demonstrates how to manipulate ASPxHtmlEditor View Areas by CustomToolbarButton.

js
function OnCustomCommand(s, e) {
    if(e.commandName == "close") {
        cp.PerformCallback("closed");
    }
    if(e.commandName == "open" || e.commandName == "new")
        if(confirm("Are you sure?"))
        cp.PerformCallback("opened");
}
aspx
<dx:ASPxCallbackPanel ID="cp" runat="server" ClientInstanceName="cp" OnCallback="cp_Callback">
    <PanelCollection>
        <dx:PanelContent ID="PanelContent1" runat="server" SupportsDisabledAttribute="True">
            <dx:ASPxHtmlEditor ID="htmlEditor" runat="server">
                <ClientSideEvents CustomCommand="OnCustomCommand" />
                <Toolbars>
                    <dx:HtmlEditorToolbar>
                        <Items>
                            <dx:CustomToolbarButton CommandName="new" Text="New" />
                            <dx:CustomToolbarButton CommandName="open" Text="Open" />
                            <dx:CustomToolbarButton CommandName="save" Text="Save" />
                            <dx:CustomToolbarButton CommandName="close" Text="Close" />
                        </Items>
                    </dx:HtmlEditorToolbar>
                </Toolbars>
            </dx:ASPxHtmlEditor>
        </dx:PanelContent>
    </PanelCollection>
</dx:ASPxCallbackPanel>
csharp
protected void Page_Load(object sender, EventArgs e) {
    if(!IsPostBack && !IsCallback)
        Session["ViewVisible"] = false;
    if(Session["ViewVisible"]!=null) {
            htmlEditor.Settings.AllowHtmlView = (bool)Session["ViewVisible"];
            htmlEditor.Settings.AllowPreview = (bool)Session["ViewVisible"];
    }
}
protected void cp_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e) {
    if(e.Parameter == "opened") {
        htmlEditor.Settings.AllowHtmlView = true;
        htmlEditor.Settings.AllowPreview = true;
        Session["ViewVisible"] = true;
    }
    if(e.Parameter == "closed") {
        htmlEditor.Settings.AllowHtmlView = false;
        htmlEditor.Settings.AllowPreview = false;
        Session["ViewVisible"] = false;
    }
}
vb
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    If (Not IsPostBack) AndAlso (Not IsCallback) Then
        Session("ViewVisible") = False
    End If
    If Session("ViewVisible") IsNot Nothing Then
            htmlEditor.Settings.AllowHtmlView = DirectCast(Session("ViewVisible"), Boolean)
            htmlEditor.Settings.AllowPreview = DirectCast(Session("ViewVisible"), Boolean)
    End If
End Sub
Protected Sub cp_Callback(ByVal sender As Object, ByVal e As DevExpress.Web.CallbackEventArgsBase)
    If e.Parameter = "opened" Then
        htmlEditor.Settings.AllowHtmlView = True
        htmlEditor.Settings.AllowPreview = True
        Session("ViewVisible") = True
    End If
    If e.Parameter = "closed" Then
        htmlEditor.Settings.AllowHtmlView = False
        htmlEditor.Settings.AllowPreview = False
        Session("ViewVisible") = False
    End If
End Sub

See Also

ExecuteCommand(commandName, parameter, addToUndoHistory)

CommandExecuted

HTML Editor

ASPxClientHtmlEditor Class

ASPxClientHtmlEditor Members