New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Customizing InsertParagraph Command to Insert Paragraph Tags in RadEditor with NewLineMode Set to DIV

Updated on Jun 1, 2026

Environment

Product Editor for UI for ASP.NET AJAX
Version Current

Description

When using the RadEditor with NewLineMode set to DIV, the InsertParagraph tool inserts <div> tags instead of <p> tags. This behavior doesn't align with the need to insert a proper <p> tag in specific scenarios while maintaining the NewLineMode behavior as DIV.

This knowledge base article also answers the following questions:

  • How to insert <p> tags in RadEditor with NewLineMode set to DIV?
  • How to customize the InsertParagraph command in RadEditor?
  • How to avoid creating <div> tags when inserting a paragraph in RadEditor?

Solution

To ensure the InsertParagraph command inserts <p> tags while keeping NewLineMode set to DIV, customize the InsertParagraph command using the OnClientCommandExecuting event. Follow these steps:

  1. Add the following JavaScript code to customize the InsertParagraph command:
javascript
function OnClientCommandExecuting(editor, args) {
    if ("InsertParagraph" === args.get_commandName()) {
        editor.pasteHtml('<p><span id="_reSelectionMarker"></span></p>');

        var marker = editor.findContent("#_reSelectionMarker").get(0); // Get the marker
        var range = editor.getDomRange();
        range.selectNodeContents(marker); // Select the marker's contents
        range.collapse(false); // Collapse to the end
        range.select(); // Make the range visible
        marker.parentNode.removeChild(marker); // Remove the marker
        args.set_cancel(true); // Prevent the default InsertParagraph behavior
    }
}
  1. Attach the OnClientCommandExecuting event to the RadEditor instance:
html
<telerik:RadEditor runat="server" ID="RadEditor1" NewLineMode="DIV" OnClientCommandExecuting="OnClientCommandExecuting">
    <Content>
        <div>Sample content</div>
    </Content>
</telerik:RadEditor>

This code overrides the default InsertParagraph command to insert a <p> tag and ensures that the cursor is correctly positioned after the inserted paragraph.

See Also