Skip to main content

InsertContentFromServerCommand.execute(requestId) Method

Executes the InsertContentFromServerCommand command with the specified parameters.

Declaration

execute(
    requestId: string,
    position?: number,
    subDocumentId?: number,
    callback?: (interval: Interval) => void
): boolean

Parameters

Name Type Description
requestId string

An string value identifying the request to the server.

position number

A value that specifies the position where to insert content to the active sub-document.

subDocumentId number

A value that identifies the target sub-document.

callback (interval: Interval) => void

A function to be executed after a content is inserted. The interval parameter returns an object that contains the inserted content’s length and position.

Returns

Type Description
boolean

true if the command has been successfully executed; false if the command execution has failed.

Remarks

The command triggers the server-side InsertContentToClient event. Use its handler to create a server-side model via the RichEditDocumentServer class (see Word Processing Document API) and pass it to the client using the Result parameter as demonstrated in the code example below:

<dx:ASPxButton runat="server" ID="InsertText" Text="Insert Text">
    <ClientSideEvents Click="onInsertTextClick" />
</dx:ASPxButton>
<dx:ASPxButton runat="server" ID="InsertModel" Text="Insert Model">
    <ClientSideEvents Click="onInsertModelClick" />
</dx:ASPxButton>
<dx:ASPxRichEdit ID="ASPxRichEdit1" ClientInstanceName="richEdit" runat="server" 
    WorkDirectory="~\App_Data\WorkDirectory" OnInsertContentToClient="ASPxRichEdit1_InsertContentToClient">
</dx:ASPxRichEdit>
function onInsertTextClick() {
    richEdit.commands.insertContentFromServer.execute('text', 0, richEdit.document.mainSubDocument.id);
}
function onInsertModelClick() {
    richEdit.commands.insertContentFromServer.execute('model', 0, richEdit.document.mainSubDocument.id);
}
protected void ASPxRichEdit1_InsertContentToClient(object sender, DevExpress.Web.ASPxRichEdit.InsertContentToClientEventArgs e) {
    if (e.RequestId == "text") {
        e.Result = "Text To Insert";
    }
    if (e.RequestId == "model") {
        var docServer = new RichEditDocumentServer();
        var document = docServer.Document;

        document.AppendText("Model To Insert");
        DocumentRange myRange = document.Paragraphs[0].Range;
        CharacterProperties charProps = document.BeginUpdateCharacters(myRange);
        charProps.FontSize = 30;
        charProps.Bold = true;
        document.EndUpdateCharacters(charProps);
        e.Result = document;
    }
}
See Also