CJ de Vos

Programming solutions with ASP.Net

AJAX Extender for TinyMCE continued

The code for this article and a sample website can be downloaded here. An online version of the sample website can also be found at http://www.cdevos.nl/examples/example1.aspx.
This article is a continuation of the previous AJAX Extender for TinyMCE which can be found http://weblogs.asp.net/cjdevos/archive/2008/03/03/ajax-extender-for-tinymce-including-fix-for-updatepanels.aspx

The download provided does not contain tinymce. Please download it seperately.

After I published the previous AJAX Extender it got quite some attention, questions and remarks and was obviously wanted by the community. Because of this reason and my own frustrations with the limitations of the current extender I used some spare time to create a new version with options to easily configure a tinymce editor on any textarea element, totally independent of the other element.

The results of all the work can be found in the sample website.

All there is to adding a tinymce editor to any textarea element looks like:

<asp:textbox runat="server" TextMode="MultiLine" id="Textbox1" Text="This is some content that will be editable with TinyMCE." />
<tm:TinyMCETextBoxExtender ID="TinyMCETextBoxExtender1"
    runat="server"
    TargetControlId="content"
    />
 

Customization of the control can be obtained by using the InitList property and adding the elements much like:

<asp:textbox runat="server" TextMode="MultiLine" id="content" Text="This is some content that will be editable with TinyMCE." />
<tm:TinyMCETextBoxExtender ID="TinyMCETextBoxExtender1" 
    runat="server"
    TargetControlId="content"
    Theme="advanced"
> 
    <InitList>
        <tm:TinyMCETextBoxInit Var="Plugins" Value="safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template" />
        <tm:TinyMCETextBoxInit Var="Theme_Advanced_Buttons1" Value="bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink" />
        <tm:TinyMCETextBoxInit Var="Theme_Advanced_Buttons2" Value="" />
        <tm:TinyMCETextBoxInit Var="Theme_Advanced_Buttons3" Value="" />
        <tm:TinyMCETextBoxInit Var="Theme_Advanced_Buttons4" Value="" />
        <tm:TinyMCETextBoxInit Var="Theme_Advanced_Toolbar_Location" Value="Top" />
        <tm:TinyMCETextBoxInit Var="Theme_Advanced_Toolbar_Align" Value="Left" />
        <tm:TinyMCETextBoxInit Var="Theme_Advanced_Statusbar_Location" Value="Bottom" />
        <tm:TinyMCETextBoxInit Var="Extended_Valid_Elements" Value="a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]" />
    </InitList>
</tm:TinyMCETextBoxExtender>
 

And it gets even better when you put the above in a .skin file

<asp:textbox runat="server" TextMode="MultiLine" id="content" Text="This is some content that will be editable with TinyMCE." />
<tm:TinyMCETextBoxExtender ID="TinyMCETextBoxExtender1"
    runat="server"
    TargetControlId="content"
    SkinID="CustomSkin"
    />
 

Comments

SovereignLizard said:

Hi siets... I found you original article a week or so ago. Even though I noticed you were still working and enhancing the original extender I started to use your code as a base. Have you thought about starting a codeplex project for it because of the great benefit your code could provide to the community?

Here are a few missing pieces that I tweaked in your original code and believe would make it better:

1. Add a "tinyScriptPath" property so that the location of "tiny_mce.js" can be dynamically provided.

2. Implement GZip compression.

3. By default the .NET 2.0 framework has validateRequest="true", this caused me a bit of a problem when it passed the html created by tinyMCE to my codebehind. So I implemented <a href="tinymce.moxiecode.com/.../viewtopic.php fix from the MoxieCode forums</a>.

I added the following methods to the behavior.js in the TinyMCETextBox namespace:

<code>

TinyMCETextBox.dotNetCustomCleanup = function (type, value) {  

if (type == "insert_to_editor") {  

value = value.replace(/&lt;/gi,"<");

value = value.replace(/&gt;/gi,">");

}

return value;

}

TinyMCETextBox.dotNetCustomSaveContent = function (element_id, html, body) {  

html= html.replace(/</gi,"&lt;");

html= html.replace(/>/gi,"&gt;");

return html;

}

</code>

Finally I added the following to the init method:

,cleanup_callback : "TinyMCETextBox.dotNetCustomCleanup",save_callback : "TinyMCETextBox.dotNetCustomSaveContent"

# June 19, 2008 5:06 PM

SovereignLizard said:

Oh... one more thing I had to tweak.

Becase an extender is for a specific control or "textbox" and you're using "mceAddControl" the correct mode to use would be "none".

Source:

wiki.moxiecode.com/.../mode

# June 19, 2008 5:10 PM

siets said:

SovereignLizard,

Thank you very much for your thorough examination and feedback. I really appreciate it.

1.tinymceScriptPath

Good idea!

2. GZIP compression

Good idea as well. I wanted the future for this version already but it seemed to have totally slipped my mind.

3. Bypass validateRequest

Although I can see where it comes from, and it is a valid point, I do not completely agree with this statement.

Posted HTML should never be trusted by any website and the validateRequest option makes sure it is not. Developers should know about this option and use it appropriately. This extender should not bypass validateRequest.

I'll think about adding this option but I will make sure that an additional property (AllowPostedHTML) is checked before the code is executed on the client and server.

4. Proper usage of tinymce mode property

I'll look into it.

5. Codeplex project

I'll look into it. It never occured to me that it could be an OS project. I'm not at all familiar with open source as I usually deal with closed source. Hence probably why there is a lack of comments in my code ;-)

# June 19, 2008 5:52 PM

SovereignLizard said:

I looked at your new version a bit, looks good. I like the option enum you implemented.

I definetly agree about "validateRequest" I don't believe it should EVER be turned off. The problem was, in my case, unless I came up with an alternative solution that would have been my only choice. The way I implemented is using tinyMCE core functionality (cleanup_callback and save_callback) events. All it is doing is changeing all <> characters into their html equivilants so even if the code was printed directly to a website it would only display it as such and not interperate it as html or script code. Not only that, but if you use tinyMCE correctly it prevents unauthorized tags from being passed.

That's just my "two cents" ;).

# June 19, 2008 7:10 PM

moghazali said:

Hi,

It was a great help to find this page after doing a lot of search for some good and easy way to have a Rich Text Box within my ASP.NET application.

Although, it took some time to configure things related to TinyMCE and your provided code had to be re-compiled against the latest download of Ajax Control Toolkit to work, but at last it wask working and it was breeze for me that it worked so smoothly on the localhost.

However, when I uploaded my site to the production server and I tested the page with the TinyMCE Editor along with your Extender Control, I am being presented with two JavaScript Error messages on load. The modified screen-shots are available here in the sequence they appear:

moghazali.googlepages.com/2008-06-21-TinyMceExtenderJsError1On.bmp

moghazali.googlepages.com/2008-06-21-TinyMceExtenderJsError2On.bmp

Nothing else happens after these errors and editor is displayed and I have even tested that appropriate button submission/postback is working fine.

The above errors are displayed only in IE 7 and no such errors were prompted when I tested with Firefox. My current work environment is VS 2008 with ASP.NET 3.5.

Please guide to remove these errors so my production site would be free from errors presented to users.

Thank you in anticipation for your help.

# June 20, 2008 7:18 PM

siets said:

1. Did you upload the control?

2. Does your online web.config contain all the configuration elements required to get AjaxControlToolkit to work? Some elements (like ScriptResource.axd) are used to extract the resource from the assembly.

# June 21, 2008 5:50 AM

Stuart said:

Hi...

I'm desperately trying to get this working in ASP.NET 3.5 (VS2008) but when I rebuild the site I get this error...

Unable to create type 'cc:TinyMCETextBoxExtender'. Could not load file or assembly 'AjaxControlToolkit, Version=1.0.10920.32880, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I've copied TinyMCETextBox.dll from the download into my BIN folder. I'm using a AJAX enabled site so already have AjaxControlToolkit.dll but it's version 3.0.20229.0 rather than 1.0.10920.0. My web.config looks fine btw.

Any help would be really appreciated.

Thanks

# June 24, 2008 5:30 PM

siets said:

Hi Stuart,

Please open the project. Remove the AjaxControlToolkit reference (and dll) and recreate the reference to the newer AjaxControlToolkit that you are using.

Once recompiled it should work.

Cheers,

CJ.

# June 25, 2008 6:34 AM

Stuart said:

Hi CJ...

Thank you very much for your help, I really appreciate it. It's now working perfectly.

Stuart

# June 25, 2008 1:59 PM

Peter said:

Does this control only work with version 1 of the Ajax Control Toolkit? I can't seem to get it to work with v3.5

# July 1, 2008 4:29 PM

Peter said:

Oops, I forgot you get the source code with the download! Ignore my previous post, I just changed the reference in the project and recompiled

# July 1, 2008 4:35 PM

Peter said:

Is anyone else getting a 'e is null' javascript error (in the tiny_mce file) when using the 3.5 ajax control toolkit? As far as I can see 'e' is a reference to the tinymce textarea. The postback doesn't hold the value in the textarea either...

# July 2, 2008 6:23 PM

Dave said:

Thanks for the awesome work! I'm having great success  with IE, but not working properly with Firefox 3.0. After a first postback, the editor disappears. After another postback, it works again. I haven't really delved into the code but I'm not sure what is up... any theories? The problem can be easily reproduced by visiting the demo site above in FF 3 and hitting the postback button.

# July 9, 2008 11:51 AM

acoldone said:

I'm getting the "e is null" error in firefox when I just take take the sample site, use one control in an update panel and convert it to use master pages. The first time I submit I get the error. But then if I submit again the error doesn't appear?

# July 10, 2008 4:12 PM

zegenie said:

Have a look at this url for more information about that issue:

tinymce.moxiecode.com/.../viewtopic.php

# July 10, 2008 6:58 PM

Peter said:

The 'e is null' error is even happening on the sample site!

www.cdevos.nl/.../example1.aspx

# July 14, 2008 11:20 AM

P Singh said:

Hmm, I'm not sure what's going on here.  I've been digging for a little while now, and have still come up empty as to why this isn't working.  In IE7 the RTE doesn't even load.  In FF2 it loads, but Firebug throws an error.

TinyMCETextBox is not defined

$create(TinyMCETextBox.TinyMCETextBoxBehavior...)

I looked at it seems that the Type.registerNamespace isn't being executed.  Somehow the js resource for behaviors isn't being loaded?  I checked the project & it's an embedded resource.

I figured I'd leave a post here & see if it's my own stupidity doing this, or if it's a genuine bug.  I'd appreciate any feedback I can get, and thanks a lot for the control!  The effort is very appreciated.  If I do anything different with it, I'll certainly let you know.

# July 16, 2008 5:42 AM

vhpinfl said:

I'm having a problem with this extender. I have a treeview of files in a directory that will be loaded into the editor, but when I click on a file and load its contents into the editor, tinyMCE disappears and only shows the textarea. What could be the problem here?

Thanks

# July 16, 2008 11:30 AM

Bengan said:

This extender is great! I have used the first version for a while, but after the release of Firefox 3 it stoped work properly. The toolstrip in TinyMCE is visible but the textarea part is laying behind the controle and is not visible. I have downloaded this later version and discovered that the problem remains.

Does anyone have the same problem or is it somehing in my settings I can change to resolve this issue.

# July 17, 2008 10:40 AM

vhpinfl said:

I should have mentioned that it works fine in IE7, but not in FF3. It only not loads the first time a node from the treeview is clicked. After that, each selection properly loads into the editor.

Anybody else having issues with FF3?

# July 17, 2008 2:23 PM

Dave said:

I'm not having any luck with FF3 either (same as vhpinfl). I'm going to take a look at the code and see, but I'm not sure if I'll be able to figure it out or not. Anyone know what the problem might be?

# July 24, 2008 10:15 AM

siets said:

Have been on quite a nice holiday and noticed the many lot of comments. Thank you!

Again - it might take a little while but I have made note of your comments and will work on the implementation for VS2008, AjaxControlToolkit3.5 and even FireFox 3.

When released it will probably become a community project as well so it is easier for others to help.

# July 27, 2008 7:43 AM

furiousp said:

Sounds great, thanks!

# July 31, 2008 9:39 AM

Serega said:

Good extender, but he need ability to specify path for tinymce directory

# August 6, 2008 8:12 AM

Cioce said:

Nice work, question: is this work also on opera and firefox? i tested, it seems to be working ok only in ie, on opera anf ff, editor is gone.

# August 13, 2008 11:24 AM

Kowboy33 said:

Above someone siad they got the extneder to work wiht 2008/3.5 and the newer ajax toolkit. I removed the reference and re added it, and it still does not work?

Is there any solution yet?

And, since I can't get it to work, I'm wondering if this will allow postback and not get the 500 error?

# August 13, 2008 10:48 PM

Olle said:

Great work, Siets. Hope your work is doing progress. I would really appreciate if you put the project on Codeplex as you hinted in a earlier post.

I think alot of developers who used this piece of code has done some modifications to it that makes it even better.

If we had it on codeplex we could all contribute to the source.

# September 8, 2008 4:59 AM

siets said:

There is an easy fix for FireFox 3. Change the mode attribute to none, instead of textareas. This seems to fix the problem - but I will delve a bit more into it now I have the time available again.

# September 23, 2008 7:59 AM

sunrunner100 said:

First off, I wanted to thank you for making this extender, it really helped me out.  I was just curious if there is any way to get it to work with a ModalPopupExtender... I keep throwing a "Microsoft JScript runtime error: 'DOM.get(...)' is null or not an object" exception every time a postback occurs with a hidden panel attached to a ModalPopupExtender.

# October 8, 2008 6:31 PM

sunrunner100 said:

Never mind, this was my mistake... remember to turn your smart navigation off when using this control!

# October 9, 2008 12:14 PM

rkirk92 said:

I have rebuilt the extender with the newest version of the AJAX Control toolkit, changed the mode attribute to none for Firefox and added the black o2k7 skin.  All is well except for posting back in an update panel in Firefox 3.  When I do a partial postback the editor is reloaded without the data.  If I do a full page postback the data returns.  Do you have any ideas on a fix for this issue?

# October 17, 2008 1:10 PM

Derek said:

Noticed an odd little bug, when you add stuff to the init list via the extender, when adding var's that take a boolean value, the extender will pass the following to tinyMCE.init:

var : 'true' or var : 'false'...

Which is always true... since any non null string returns evaluates to true in javascript. This is a big time bug when needing to turn off certain tinyMCE (in my case converting url's)

# October 23, 2008 4:59 PM

Derek said:

Although, that can be fixed by leaving the string empty, which javascript evaluates to false. ;)

# October 23, 2008 5:35 PM

iconite said:

Hi,

I've downloaded the last version of this extender and tried to deploy it on vs2008 .net 3.5.

Went through the step of opening the project, replace the Ajax 1 reference with Ajax 3 refence, but still I'm getting an error when trying to run it...

basically it returns an object reference not set to an instance of an object at: this.Page.Header.Controls.Add(Include);

wheren header is returning null.

Am I missing some type of configuration? PLS help!!!!

Thanks A lot

# October 24, 2008 7:13 AM

Haz said:

Have someone been able to find a workaround when using ASP.NET 3.5 and its AJAX toolkit?

I have tried the suggestions above of adding reference etc, but I still get the following compile error in VS2008:

Error 2 Could not load file or assembly 'AjaxControlToolkit, Version=1.0.10920.32880, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

# October 24, 2008 3:51 PM

Pedro said:

Hi people,

I've an js error like: tinyMCE is not defined

I use VS2008/.NET3.5....and I use AjaxToolKit v3.

# January 14, 2009 1:36 PM

caileanadriyel said:

I tested your live example1 in Firefox 3 and find that the TinyMCE disappears on postback. Has there been any resolution for Firefox 3 yet?

# February 10, 2009 2:39 PM

... said:

Interessante Informationen.

# March 4, 2009 6:18 AM

... said:

Sehr wertvolle Informationen! Empfehlen!

# March 15, 2009 11:02 PM

dcallan said:

I only have visual web developer and can't build dlls. I need a version compat with 3.0.20820 ajaxcontroltoolkit.dll

# May 6, 2009 12:25 PM

Manish said:

How can I access the value of tinyMCE editor in codebehind to save it to the database?

# May 15, 2009 5:44 AM

wertyk said:

Is very good control, but how to decide the issue with the error data?

# May 25, 2009 8:29 AM

Dave Sussman said:

I just want to add my thanks for this extender. Having thought I'd cured my tinyMCE/UpdatePanel issues, I found this which really did solve them. I did have to recompile it because I have a customised version of the AjaxToolkit, but it worked perfectly. Thanks.

# May 28, 2009 8:46 AM

Tod said:

New Ajax Toolkit and Im getting the error:

Could not load file or assembly 'AjaxControlToolkit, Version=3.0.20820.16598,

# June 5, 2009 10:16 AM

Tod said:

Its OK, I just updated the project to .net 3.5 and added the latest AJAX Toolkit

# June 5, 2009 10:25 AM

dcallan said:

It works good but a little bug occurs if I turn off partialrendering on the scriptmanager so I can see exceptions properly.

# June 14, 2009 5:11 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)