Ticket #2143 (new Bug)

Opened 2 years ago

Last modified 18 months ago

FCKEditor.GetInstance and Dynamically loaded Web/User Controls.

Reported by: Kressilac Owned by:
Priority: Normal Milestone:
Component: Server : ASP.Net Version:
Keywords: Cc:

Description

When using FCKEditor in a dynamically loaded WebControl the submit problem in  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.  MSDN Reference on UniqueID

Change History

Changed 2 years ago by Kressilac

            FCKeditorAPI.GetInstance(id).UpdateLinkedField();
            
            if (FCKBrowserInfo.IsIE7 == true)
                FCKeditorAPI.GetInstance(ieid).UpdateLinkedField();

Use the above code instead of the branch in the last code block of the original message.

Changed 18 months ago by arczi

  • component changed from General to Server : ASP.Net
Note: See TracTickets for help on using tickets.