Click here to Skip to main content
15,886,565 members
Articles / Web Development / HTML

Set Content inside AJAX HTMLEditor and EditorExtender using JavaScript

5 Mar 2014CPOL1 min read 24.7K   632   7   2
If you want to set text inside AJAX HTMLEditor or HTMLEditorExtender, then this is the right place. Enjoy the tip.

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.

JavaScript
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

    JavaScript
    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.

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

Doubts/Queries/Modifications?

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

Image 4 Image 5

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Proud Indian | Author | TEDx Speaker | Microsoft MVP | CodeProject MVP | Speaker | DZone Most Valuable Blogger| jsfiddler

My Website

taditdash.com

Programming Community Profiles

jsfiddle | Stack Overflow

Social Profiles

Facebook | Twitter | LinkedIn

Awards


  1. DZone Most Valuable Blogger
  2. Microsoft MVP 2014, 2015, 2016, 2017, 2018
  3. Code Project MVP 2014, 2015, 2016
  4. Star Achiever of the Month December 2013
  5. Mindfire Techno Idea Contest 2013 Winner
  6. Star of the Month July 2013

Comments and Discussions

 
QuestionHTML Code Pin
ravi kumar Mishra26-May-14 1:57
ravi kumar Mishra26-May-14 1:57 
AnswerRe: HTML Code Pin
Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)20-Jul-14 18:34
protectorTadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)20-Jul-14 18:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.