Set Content inside AJAX HTMLEditor and EditorExtender using JavaScript

HTML Table set inside Editor and EditorExtender

HTML Table set inside Editor and EditorExtender


If you want to set text inside AJAX HTMLEditor or HTMLEditorExtender, then this is the right place. Enjoy the Tip.

What?

I am going to talk about ASP.NET Ajax HTMLEditor and HTMLEditorExtender.

So, what is the issue?

There are two types of Editors available.

  1. HTMLEditor
  2. HTMLEditorExtender

If you are going to set Text or HTML inside the Edit Panel of any of these Controls, then you can’t do this directly using document.getElementById("EditorID");. That is because the HTMLEditor or HTMLEditorExtender are rendered on Browser with the help of many divs.

Then what is the Logic?

We need to identify the div which is used to the actual content and set the Text or HTML inside it. The way of setting this inside Editor and Extender will be different.

For HTMLEditor, let’s identify the Edit Panel in source HTML

Ajax HTMLEditor Browser Rendered View

Ajax HTMLEditor Browser Rendered View

For HTMLEditorExtender, let’s identify the Edit Panel in source HTML

Ajax HTMLEditorExtender Browser Rendered View

Ajax HTMLEditorExtender Browser Rendered View


So, we just need to assign Text or HTML inside these body or div.

How to do this?

For HTMLEditor

There is a method present named as set_content(), by which we can easily do this task.

var htmlEditor = $find("<%= htmlEditorDemo.ClientID %>");
htmlEditor.set_content(tableToBeSetInsideEditPanel);

Here tableToBeSetInsideEditPanel is a string containing one table Markup.

For HTMLEditorExtender

  • Using innerHTML

    First find the EditorExtender using ID, then assign the required HTML to its

    var htmlEditorExtender = $find("<%= htmlEditorExtenderDemo.ClientID %>");
    htmlEditorExtender._editableDiv.innerHTML = tableToBeSetInsideEditPanel;
  • Using jQuery .html()

    Get only the Edit Panel div by the Class Name .ajax__html_editor_extender_texteditor, then call .html() to set the required HTML inside that.

    var htmlEditorExtender = $('.ajax__html_editor_extender_texteditor');
    htmlEditorExtender.html(tableToBeSetInsideEditPanel);

Doubts/Queries/Modifications?

If you have any, feel free to comment. Please Like and Share the Blog, if you find it interesting.

Leave a comment