Skip to main content
A newer version of this page is available. .

DxRichEdit.DocumentContentChanging Event

Allows you to edit document before saving.

Namespace: DevExpress.Blazor.RichEdit

Assembly: DevExpress.Blazor.RichEdit.v21.2.dll

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

[Parameter]
public EventCallback DocumentContentChanging { get; set; }

Remarks

The Rich Text Editor updates the DocumentContent property value and raises the DocumentContentChanging and DocumentContentChanged events in the following cases:

The DocumentContentChanging event occurs before the DocumentContentChanged event. Handle the DocumentContentChanging event to edit an open document before saving and handle the DocumentContentChanged event to save the document.

The following code example handles the DocumentContentChanging event to update fields in an open document before it is saved:

<DxRichEdit @ref="@richEdit" DocumentFormat="DocumentFormat.OpenXml" 
    @bind-DocumentContent="@documentContent" DocumentContentChanging="OnDocumentContentChanging" />

@code {
    DxRichEdit richEdit;
    byte[] documentContent;

    async Task OnDocumentContentChanging() {
        /* Surround the code that contains an asynchronous operation with a try-catch block to handle
    the OperationCanceledException. This exception is thrown when an asynchronous operation is cancelled. */
        try {
            await richEdit.DocumentAPI.Fields.UpdateAllAsync(true);
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}
See Also