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

ASPxHtmlEditor.PastedImageSaving Event

Allows you to process and save the pasted binary image to the server.

Namespace: DevExpress.Web.ASPxHtmlEditor

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

Declaration

public event PastedImageSavingEventHandler PastedImageSaving

Event Data

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

Property Description
CallbackData Gets or sets a string that contains specific information (if any) to be passed from the server side to the client. Inherited from FileUploadCompleteEventArgs.
Cancel Indicates if the action which raised the event should be canceled. Inherited from FileSavingEventArgs.
ErrorText Gets or sets the error text. Inherited from FileUploadCompleteEventArgs.
FileName Gets or sets the name of the uploaded file. Inherited from FileSavingEventArgs.
InnerHTML Gets or sets HTML content (inner HTML) that will be rendered inside the HTML tag specified in the PastedImageSavingEventArgs.TagName property.
IsValid Gets or sets a value specifying whether the uploaded file passes validation. Inherited from FileUploadCompleteEventArgs.
OutputStream Set this property to change the original file content. Inherited from FileSavingEventArgs.
SavedFileUrl Gets or sets the URL of the saved file. Inherited from FileSavingEventArgs.
TagName Gets or sets the root HTML element of the resulting HTML element.
UploadedFile Gets the uploaded file object related to the event. Inherited from FileUploadCompleteEventArgs.

The event data class exposes the following methods:

Method Description
SetAttribute(String, String) Specifies any attribute (including the data-* attributes) of the resulting HTML element.
SetStyleAttribute(String, String) Specifies a CSS property in the ‘style’ attribute of the resulting HTML element.

Remarks

Handle the PastedImageSaving event to process the pasted binary image before it is saved to the server. This event also fires during the server side processing of the pasted RTF content in case it contains images. To process other images, video, and flash files before saving them to the server after uploading, handle the ASPxHtmlEditor.ImageFileSaving event (that fires after the PastedImageSaving event if the IsValid property is set to true or the FileSavingEventArgs.Cancel property is set to false).

Setting the IsValid property to false and specifying the ErrorText property fires the client ASPxClientHtmlEditor.CallbackError event.

The following examples illustrate how to use the PastedImageSaving event to process and customize the pasted binary image.

  • Customized image styles

    protected void ASPxHtmlEditor1_PastedImageSaving(object source, PastedImageSavingEventArgs e) {
        e.SetStyleAttribute("max-width", "100%");
        e.SetStyleAttribute("border", "1px solid #aaa");
    }
    
    protected void ASPxHtmlEditor1_PastedImageSaving(object source, PastedImageSavingEventArgs e) {
        if (!e.IsValid) {
            e.SetAttribute("data-isvalid", "false");
            e.SetAttribute("src", "broken-image.png");
            e.SetAttribute("alt", "broken image");
        }
    }
    
  • Changed render for the image element

    protected void ASPxHtmlEditor1_PastedImageSaving(object source, PastedImageSavingEventArgs e) {
        if (!e.IsValid) {
            e.TagName = "DIV";
            e.InnerHTML = "<img src='broken-image.png' />";
            e.SetStyleAttribute("border", "1px dotted #f00");
        }
    }
    

Note

The PastedImageSaving event is in effect if the ASPxHtmlEditorSettings.AllowSaveBinaryImageToServer property is set to true.

See Also