Opened 12 years ago

Closed 8 years ago

#2143 closed Bug (expired)

FCKEditor.GetInstance and Dynamically loaded Web/User Controls.

Reported by: Derek Licciardi 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 (3)

comment:1 Changed 12 years ago by Derek Licciardi

            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.

comment:2 Changed 11 years ago by Artur Formella

Component: GeneralServer : ASP.Net

comment:3 Changed 8 years ago by Wiktor Walc

Resolution: expired
Status: newclosed

There is a new ASP.NET control available: CKEditor for ASP.NET. The old control (FCKeditor.Net) is no longer maintained, so I'm closing the ticket.

If you find a similar bug in CKEditor 3.x, please create a new ticket for it.

Note: See TracTickets for help on using tickets.
© 2003 – 2019 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy