﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
2143	FCKEditor.GetInstance and Dynamically loaded Web/User Controls.	Derek Licciardi		"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]"	Bug	closed	Normal		Server : ASP.Net		expired		
