Clipboard Cleanup in ASP.NET Core Rich Text Editor Control

18 Nov 20181 minute to read

The Rich Text Editor supports automatic cleanup of clipboard content during copy (Ctrl + C) and cut (Ctrl + X) operations. When this feature is enabled, unwanted inline styles are automatically removed from the clipboard content while preserving important structural elements such as tables, lists, and images. You can enable this behavior using the enableClipboardCleanup property.

When enableClipboardCleanup is set to true, copy and cut operations are intercepted to remove unwanted inline styles. When set to false the browser’s default copy and cut behavior applies.

For a cleaner editing experience, enableClipboardCleanup is true by default.

Customizing Copied/Cut Content

You can use the beforeClipboardWrite event, which fires before content is written to the clipboard during copy or cut operations. This event lets you to modify the HTML and plain-text representations of the content and also determine whether the action is a copy or a cut.

In this example, the beforeClipboardWrite event is used to customize the selected content only during a copy operation, while the cut operation remains unaffected. To observe this behavior, try copying any text within the Rich Text Editor.

Best Practices & Troubleshooting

Best Practices

  • Use beforeClipboardWrite sparingly — heavy processing can slightly delay Ctrl+C.

Common Issues

  • “Event not firing” → Make sure you’re using the correct event name beforeClipboardWrite (camelCase in Core).