#2143: FCKEditor.GetInstance and Dynamically loaded Web/User Controls.
-----------------------+----------------------------------------------------
Reporter: Kressilac | Type: Bug
Status: new | Priority: Normal
Milestone: | Component: General
Version: | Keywords:
-----------------------+----------------------------------------------------
When using FCKEditor in a dynamically loaded WebControl the submit problem
in [http://dev.fckeditor.net/ticket/234 234] appears under both Firefox
and IE7.
Example Code:
{{{
protected override void CreateChildControls()
{
String UserControlLocation = "~/MyEditorWebControlLocation";
Control ctrl = LoadControl(ResolveClientUrl(UserControlLocation));
if (ctrl != null)
{
ctrl.ID = "AGeneratedID";
placeholder.Controls.Add(ctrl);
}
}
}}}
What happens when you do this is that the javascript cannot find the
instance of the FCKEditor burried in the UserControl. For FCKEditor in
Firefox, the FCKUpdateLinkedField(id) fix works properly when the
registered submit statement is the following:
{{{
function FCKUpdateLinkedField(id)
{
try
{
if(typeof(FCKeditorAPI) == "object")
{
FCKeditorAPI.GetInstance(id).UpdateLinkedField();
}
}
catch(err)
{
}
}
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
}}}
with the register method called in the PreRender method of the User
Control.
{{{
ScriptManager.RegisterOnSubmitStatement(this, this.GetType()
, "FCKEditorForceUpdate" + WebEditor.ClientID
, "FCKUpdateLinkedField('" + WebEditor.ClientID + "');");
}}}
Two notes, remember to uniquely name your RegisterOnSubmitStatements if
there are multiple FCKEditors on the page. Additionally, the code here
assumes an Ajax page so adjust accordingly. The problem with the above
code, is that it does not work under IE7. In fact this code generates
Javascript bugs. The fix is simple:
{{{
ScriptManager.RegisterOnSubmitStatement(this, this.GetType()
, "FCKEditorForceUpdate" + WebEditor.ClientID
, "FCKUpdateLinkedField('" + WebEditor.UniqueID + "');");
}}}
By referencing UniqueID instead of ClientID the FCKUpdateLinkedField()
call will find the editor and work properly. Unfortunately that breaks
Firefox. The only solution I found was to pass both UniqueID and ClientID
into the FCKUpdateLinkedField() call and test the browser type in the
function. This enables both browsers to post back properly with the text
from the editor. :( I'm hoping there's a fix here somewhere and that
bringing this issue to light makes FCK better.
{{{
ScriptManager.RegisterOnSubmitStatement(this, this.GetType()
, "FCKEditorForceUpdate" + WebEditor.ClientID
, "FCKUpdateLinkedField('" + WebEditor.ClientID + "', '" +
WebEditor.UniqueID + "');");
}}}
with modified FCKUpdateLinkedField() code.
{{{
function FCKUpdateLinkedField(id, ieid)
{
try
{
if(typeof(FCKeditorAPI) == "object")
{
if (FCKBrowserInfo.IsIE7)
FCKeditorAPI.GetInstance(ieid).UpdateLinkedField();
else
FCKeditorAPI.GetInstance(id).UpdateLinkedField();
}
}
catch(err)
{
}
}
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
}}}
Hope this helps. [http://msdn2.microsoft.com/en-
us/library/3hc29e2a(VS.80).aspx MSDN Reference on UniqueID]
--
Ticket URL: <http://dev.fckeditor.net/ticket/2143>
FCKeditor <http://www.fckeditor.net>
The text editor for Internet
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
FCKeditor-Trac mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fckeditor-trac