locked
FYI: How to make FCKeditor work in an UpdatePanel RRS feed

  • Question

  • User949867985 posted

    Hi all,

    I've spent weeks (slight exaggeration) trying to get FCKeditor to work in an UpdatePanel. Even with the latest FCK code (2.3.1), the changes to the content of the editor are lost on partial postback. (I think this may only be a problem in Firefox).

    Anyway, today I found the solution and I thought I'd share it with everyone:

    http://wiki.fckeditor.net/Troubleshooting#head-c83215c3393542ddc261fb2b7a64b60a41253d76

    Wish I'd looked at the Wiki earlier!

    Thursday, September 21, 2006 12:00 PM

All replies

  • User-2070978840 posted

    So you included this?

     <form ... onSubmit="MyObject.UpdateEditorFormValue(); return true;">
    
     
    Tuesday, October 24, 2006 3:14 PM
  • User1408118820 posted

    Here's how I got it working with FCKEditor 2.3.2 (FCKEditor .NET 2.2)

    In my web control page_load code, I register the client script and add an onsubmit to my link button (called lbSave here).
     

    If Not Page.IsPostBack Then
        If Not Page.ClientScript.IsClientScriptBlockRegistered("FCKAjaxHack") Then
            Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "FCKAjaxHack", String.Format("<script type=""text/javascript"" src='{0}'></script>", ResolveUrl("~/js/FCKHack.js")))
        End If
        lbSave.Attributes.Add("onclick", "if (eval('(typeof(MyFCKObject) != \'undefined\');')){MyFCKObject.UpdateEditorFormValue(); return true;}else{return true;}")
    End If

     ...and my javascript include file (FCKHack.js) contains the following:

    // Some Class
    function MyFCKClass()
    {
            this.UpdateEditorFormValue = function()
            {
                    for ( i = 0; i < parent.frames.length; ++i )
                            if ( parent.frames[i].FCK )
                                    parent.frames[i].FCK.UpdateLinkedField();
            }
    }
    // instantiate the class
    var MyFCKObject = new MyFCKClass();

     

    ... I changed the name of the javascript object and function from what was listed here ( http://wiki.fckeditor.net/Troubleshooting#head-c83215c3393542ddc261fb2b7a64b60a41253d76 ), since those names are a bit generic.

     

    Friday, October 27, 2006 11:54 AM
  • User-619855079 posted

    Great work...

    I'm having problems with using FCKEditor inside a DataList <edititemtemplate> using the AJAX UpdatePanel with your setup/code. I know this will be a nice one for ya. Let me know of you need code. Have fun...

     

    <ajax:updatepanel id="UpdatePanel1" runat="server">
        <contenttemplate>
            <asp:datalist id="DataList1" runat="Server" cellpadding="4" datakeyfield="id" datasourceid="SqlDataSource1" ondeletecommand="DataList1_DeleteCommand"
                oneditcommand="DataList1_EditCommand" onitemcreated="DataList1_ItemCreated" width="98%" oncancelcommand="DataList1_CancelCommand"
                onupdatecommand="DataList1_UpdateCommand">
                <edititemtemplate>
                    <fckeditorv2:fckeditor id="txtBody1" runat="server" value='<%# Eval("body") %>' toolbarset="Basic" debug="true">
                    </fckeditorv2:fckeditor>
                <edititemtemplate>
            </asp:datalist>
        </contenttemplate>
    </ajax:updatepanel>
    
    

     

    I'm also using masterpages in which just "UpdatePanel1" is actually located. the rest is in the content page or default.aspx. The same concept should still apply here...

     

     

    Friday, November 24, 2006 8:09 AM
  • User-1477417254 posted

    dear frankosaurus is not online. Last active: 10-27-2006, 8:49 PM frankosaurus

    how do that its not work for please can u explain more for me

    because i did everthing u said but not work for me

    Sunday, December 3, 2006 4:09 AM
  • User-1631095575 posted

    Firstly, frankosaurus, thanks for your sample code.

    Only i want to clarify one little bug in your code, to help amersafi.

    on this line of code:

    lbSave.Attributes.Add("onclick", "if (eval('(typeof(MyFCKObject) != \'undefined\');')){MyFCKObject.UpdateEditorFormValue(); return true;}else{return true;}")

    You put a semicolon ( ";" ) after eval function, and this generates a javascript error.

    amersafi, remove thats semicolon and be happy [:D]

    I would like to write about this on my Spanish Blog. http://www.computerapia.com

    Thanks again!

    Sunday, December 31, 2006 9:58 AM
  • User2073593117 posted

    Thanks a lot for this.

    It works perfect, except I keep getting a "FCK is not defined" in fckeditorcode_gecko.js line 35.

    Any workaround for this? This is using the latest version (2.3.2).
     

     


     

    Thursday, January 11, 2007 8:45 AM
  • User-2091047184 posted

    TchamiDK,

    I'm having the same problem. Have you found a solution?

    Wednesday, January 17, 2007 5:04 PM
  • User-2063076121 posted

    I have found the following to be a simpler solution to the same problem...

    private void Page_Load(object sender, EventArgs args)
    {
        Page.ClientScript.RegisterOnSubmitStatement(
            editor.GetType(),
            "editor",
            "FCKeditorAPI.GetInstance('" + editor.ClientID + "').UpdateLinkedField();");
    }

    You can also do it for multiple editors...

    private void Page_Load(object sender, EventArgs args)
    {
        Page.ClientScript.RegisterOnSubmitStatement(
            editor1.GetType(),
            "editor1",
            "FCKeditorAPI.GetInstance('" + editor1.ClientID + "').UpdateLinkedField();");
    
        Page.ClientScript.RegisterOnSubmitStatement(
            editor2.GetType(),
            "editor2",
            "FCKeditorAPI.GetInstance('" + editor2.ClientID + "').UpdateLinkedField();");
    }
    Friday, March 30, 2007 4:50 AM
  • User-1557892389 posted

    Josh,

    Elegant, perfect!  Works for me, thanks for the quickie solution.

     

    -Jason

    Friday, April 6, 2007 2:36 PM
  • User-2063076121 posted

    Note that after some additional testing I found a problem if the editor is ever hidden during a partial postback, there could be some javascript errors on a following postback. For example, if the editor is on one step of a multistep process in a multiview, tabcontainer, etc.

    I've posted the details and a solution at http://jlcoady.net/archive/2007/03/30/fckeditor-work-inside-updatepanel

    Friday, April 6, 2007 5:49 PM
  • User-619855079 posted

    Note that after some additional testing I found a problem if the editor is ever hidden during a partial postback, there could be some javascript errors on a following postback. For example, if the editor is on one step of a multistep process in a multiview, tabcontainer, etc.

    I've posted the details and a solution at http://jlcoady.net/archive/2007/03/30/fckeditor-work-inside-updatepanel



    Thank you for the better solution. I think the .js route, per your blog post, is a very smart choice and also minimizes multi-file-updates. Hopefully FCK will include this solution into his editor for a future release (possibly a "FCKEditor.NET" version). I will be testing this in a real-world production server on Glacsy.com and see if it performs well. If there's any bugs found or performance costs arise, I'll let you know...
    Friday, April 6, 2007 7:14 PM
  • User-1631095575 posted

    Good stuff joshcoady!, very much cleaner solution.

    Any workarround about 'FCK is not defined' on FireFox?, to reproduce this, make a Submit more than twice on Firefox...

    I recommend to use FireBug addon for FF to see this error.

    Cheers!

     

    Wednesday, April 11, 2007 10:48 AM
  • User-1145186083 posted

    Good stuff joshcoady!, very much cleaner solution.

    Any workarround about 'FCK is not defined' on FireFox?, to reproduce this, make a Submit more than twice on Firefox...

    I recommend to use FireBug addon for FF to see this error.

    Cheers

    I have this exact same problem too. I have tracked it down to the following line in fck.js:

    UpdateLinkedField : function()
    236 {
    237 FCK.LinkedField.value = FCK.GetXHTML( FCKConfig.FormatOutput ) ;
    238 FCK.Events.FireEvent( 'OnAfterLinkedFieldUpdate' ) ;
    239 },
     
    You can see this for yourself too by adding the query string "fcksource=true" to your page (providing you have the _source folder) still underneath your FCKEditor folder.
     
    I wonder if its a side effect of the fixes for Ajax? (I know I'm calling UpdateLinkedField in the version I've modified...)
    Wednesday, April 11, 2007 11:00 AM
  • User-1145186083 posted
    I wonder if its a side effect of the fixes for Ajax? (I know I'm calling UpdateLinkedField in the version I've modified...)

    Hate to answer my own question here, but yes, I can safely say that the gecko error is as a consquence of an Ajax "fix" I've implemented. I found this out by using Firebug (I was already using it before! its great isnt it! [:D]) and putting a breakpoint on line 237 above. The call stack pointed straight at my function.

    (I'm using the one off the FCKEditor WIKI. i.e. call an function on submit that does lots of calls to parent.frames[i].FCK.UpdateLinkedField())

    Back to the drawing board perhaps?

    Wednesday, April 11, 2007 11:05 AM
  • User-1145186083 posted

    I have changed my function to be :

    function () {
        if (FCK) {
            FCK.LinkedField.value = FCK.GetXHTML(FCKConfig.FormatOutput);
            FCK.Events.FireEvent("OnAfterLinkedFieldUpdate");
        }

    and it STILL doesn't work lol. Still says FCK is undefined on the if statement! I give up for now! :)

    Wednesday, April 11, 2007 11:26 AM
  • User-2063076121 posted

    Try changing your if statement to

    if(typeof(FCK) != "undefined")
     
    Wednesday, April 11, 2007 3:00 PM
  • User-2063076121 posted
    Or, just wrap it in a try..catch to suppress the error
    Wednesday, April 11, 2007 3:04 PM
  • User-1145186083 posted
    Thanks Josh. I'll give it a whirl when I get into work tomorrow (am at home at the moment). I must emphasise that that code is from FCKEditor and not my own, but I'll try the suggestions :)
    Wednesday, April 11, 2007 4:07 PM
  • User-2063076121 posted

    Are you guys trying the solution I posted to this forum or the updated version I posted here: http://jlcoady.net/archive/2007/03/30/fckeditor-work-inside-updatepanel?

    The updated version should suppress the error messages you are receiving while not forcing you to edit any of the FCK scripts.

    Let me know if it still doesnt work for you then I'll try to debug further.

    Wednesday, April 11, 2007 4:47 PM
  • User-1145186083 posted

    Hadn't looked at your bersion before. The one I was personally using was this one: http://wiki.fckeditor.net/Troubleshooting#head-c83215c3393542ddc261fb2b7a64b60a41253d76

    I think, though, that your web site may actually solve my problem as I am doing what you mentioned, and that is hiding the text editor on a partial update. I think I need to wrap my code up with:

            if(typeof(FCKeditorAPI) == "object")
    {
    ... 

    and hopefully that should solve it.

     
    Thanks again Josh.
     

    Wednesday, April 11, 2007 4:57 PM
  • User-1145186083 posted

    Hi Josh....

    I've totally removed my solution and implemented yours, and I'm still getting the error with FCK being undefined when in Firefox. Works a treat (or the error is supressed, one or the other!) in IE, but Firefox gives an error. You may only notice it if you're using Firebug...

    Thursday, April 12, 2007 3:51 AM
  • User1533174674 posted

    Hi everyone, I'm new to this, is anyone can help?

     I got the "System.NullReferenceException: Object reference not set to an instance of an object." error.

      

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    2            If Not Page.IsPostBack() Then
    3             
    4    
    5              
    6    
    7                If Not Page.ClientScript.IsClientScriptBlockRegistered("FCKAjaxHack") Then
    8                    Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "FCKAjaxHack", String.Format("<script type=""text/javascript"" src='{0}'></script>", ResolveUrl("FCKHack.js")))
    9                End If
    10   
    11   
    12               btnSubmit.Attributes.Add("onClick", "if (eval('(typeof(MyFCKObject) != \'undefined\');')){MyFCKObject.UpdateEditorFormValue(); return true;}else{return true;}")
    13   
    14           End If
    15   
    16       End Sub
    
     
    I tried to find what cause the error, but no luck.
     

    Tuesday, April 17, 2007 8:36 PM
  • User-2063076121 posted

    hmmm..it's hard to tell with the info you provided. Please turn on debugging and let us know what line of code is throwing the exception. The only place that seems like it could cause this error is the btnSubmit if there isnt a button on the page with id=btnSubmit

    Tuesday, April 17, 2007 9:30 PM
  • User1533174674 posted

      
     

    1        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    2            If Not Page.IsPostBack() Then
    3       
    4    
    5                If Not Page.ClientScript.IsClientScriptBlockRegistered("FCKAjaxHack") Then
    6                    Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "FCKAjaxHack", String.Format("<script type=""text/javascript"" src='{0}'></script>", ResolveUrl("FCKHack.js")))
    7                End If
    8    
    9    
    10               btnSubmit.Attributes.Add("onClick", "if (eval('(typeof(MyFCKObject) != \'undefined\');')){MyFCKObject.UpdateEditorFormValue(); return true;}else{return true;}")
    11   
    12           End If
    13   
    14       End Sub
    
     

    I place the editor in a updatepanel within a repeater within an other repeater. The error is on line 10. There must be something wrong with the btnSubmit button, but I'm sure I there is a button with the id "btnSubmit"

     Here is the stack trace if it helps

    [NullReferenceException: Object reference not set to an instance of an object.]
    admin_clientPMP.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\Admin\My Documents\Visual Studio 2005\WebSites\AJAXEnabledWebSite1\admin\clientPMP.aspx.vb:25
    System.Web.UI.Control.OnLoad(EventArgs e) +80
    System.Web.UI.Control.LoadRecursive() +49
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3748


    Please let me know if anyone need more information. Thanks for your time. 

    Wednesday, April 18, 2007 12:32 PM
  • User-1631095575 posted

    I suppose your button is inside a repeater.
    if look like this, you need to get the button on the Repeater_ItemDataBound event.

    protected void MyRepeater_ItemDataBound(object sender,
        System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
        RepeaterItem item = e.Item;
    
        if ((item.ItemType == ListItemType.Item) ||
            (item.ItemType == ListItemType.AlternatingItem))
        {
            (Button)btnSubmit = item.FindControl("btnSubmit");
            btnSubmit.Attributes.Add("onClick", "if (eval('(typeof(MyFCKObject) != \'undefined\');')){MyFCKObject.UpdateEditorFormValue(); return true;}else{return true;}");
        }
    }

     

    Hope it helps

    Wednesday, April 18, 2007 1:42 PM
  • User1533174674 posted

    I guess the problem is somehow I can't find the control in the child repeater.

     Here is a simple example

     

    1        Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
    2            If e.Item.ItemType = ListItemType.Item Then
    3                Dim SubRepeater As Repeater = sender
    4                Dim editbutton As Button = SubRepeater.FindControl("Button1")
    5                editbutton.Text = "dfsadfs"
    6            End If
    7        End Sub
    8    End Class
     
    The error is on line 5 "System.NullReferenceException: Object reference not set to an instance of an object"
    Is anyone have any suggestion about how I can find control in the child repeater?
    Thanks 
     
     
    Wednesday, April 18, 2007 5:02 PM
  • User-2063076121 posted

    Is the ID of your repeater Repeater1 or SubRepeater?

    Try using e.Item.FindControl instead.

    If you still cant get it to work, please also post your repeater declaration from your aspx os ascx. (The part that starts with <asp:repeater and ends with </asp:repeater>.)

    Wednesday, April 18, 2007 5:11 PM
  • User1533174674 posted

    Here is the code from aspx

     

     

    1    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
    2            <ItemTemplate>
    3                <ul>
    4                <li>
    5                    <asp:Repeater ID="Repeater2" runat="server" DataSourceID="SqlDataSource1">
    6                        <ItemTemplate>
    7                        <ul>
    8                        <li> <asp:Button ID="Button1" runat="server" Text="Button" /></li>
    9                        </ul>
    10                          
    11                       </ItemTemplate>
    12                   </asp:Repeater>
    13               </li>
    14               </ul>
    15               </ItemTemplate>
    16               </asp:Repeater>
     
    Thanks 
      
    Wednesday, April 18, 2007 5:28 PM
  • User-2063076121 posted
    Ok, so you need to be handling the ItemDataBound event from the repeater that directly contains the button. In this case it is Repeater2. Then you can use e.Item.FindControl("Button1") to get at the button.
    Wednesday, April 18, 2007 6:52 PM
  • User1533174674 posted

    This is what I did, but it still show the error

    1    Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
    2          
    3    
    4            If e.Item.ItemType = ListItemType.Item Then
    5                Dim SubRepeater As Repeater = e.Item.FindControl("Repeater2")
    6    
    7                Dim button As Button = SubRepeater.FindControl("Button1")
    8                button.Text = "My button"
    9    
    10           End If
    11   
    12       
    13       End Sub
     If I try to handing the ItemDataBound even from the Repeater2 (Child) like this:
     Protected Sub Repeater2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater2.ItemDataBound
     It shows the error "BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types
    It seems it can't find Repeater2 without Repeater1.  Do you have an idea how can I get this done?
     
    Thank you for your time. 
    Wednesday, April 18, 2007 8:11 PM
  • User-2063076121 posted

    Yes, that wont work because the button wont be instantiated until the itemdatabound event of the repeater that contains it.

    I'm not really familiar with VB, but in Repeater1_ItemDataBound try something like SubRepeater.OnItemDataBound += Repeater2_ItemDataBound; The idea is you need to subscribe the sub repeater in the itemdatabound event of the parent repeater because that is when it is instantiated. Then you should be able to get at the button in Repeater2_ItemDataBound.

    Wednesday, April 18, 2007 8:41 PM
  • User1533174674 posted
    Solved! Thank you for your advice~ I really appreciate.
    Wednesday, April 18, 2007 9:32 PM
  • User-565895123 posted

     Hi folks,

     Did anyone get to the bottom of this. I am using FCK editor inside a datalist inside an update panel. I have another standalone FCK editor on that page which works fine inside the update panel.

     EG.

    The standalone is dealt with in page_load:

    ClientScriptManager script = Page.ClientScript;
    script.RegisterOnSubmitStatement(
                editorNewMessage.GetType(),
                "editor",
                "FCKUpdateLinkedField('" + editorNewMessage.ClientID + "');"
            );

     

    I am dealing with the one inside the editItemTemplate on the ItemDataBound event.

    EG.

    protected void lstCalendarNotes_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.EditItem)
            {
                FCKeditor editorEditMessage = (FCKeditor)e.Item.FindControl("FCKeditor1");
                editorEditMessage.ToolbarSet = "Basic";

                Page.ClientScript.RegisterOnSubmitStatement(
                editorEditMessage.GetType(),
                "editor",
                "FCKUpdateLinkedField('" + editorEditMessage.ClientID + "');"
            );
            }
        }
     

    The one inside the datalist drops the changes made in the editor when it is saved using this:

    protected void lstCalendarNotes_ItemCommand(object source, DataListCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "Select":
                    lstCalendarNotes.SelectedIndex = e.Item.ItemIndex;
                    SetCalendarNotes();
                    break;
                case "Edit":
                    lstCalendarNotes.EditItemIndex = e.Item.ItemIndex;
                    SetCalendarNotes();
                    break;
                case "Delete":
                    {
                        int id = int.Parse(((HiddenField)e.Item.FindControl("hidID")).Value);
                        DiaryData.DeleteDiaryNote(id);
                        lstCalendarNotes.SelectedIndex = -1;
                        SetCalendarNotes();
                        break;
                    }
                case "Save":
                    {
                        int id = int.Parse(((HiddenField)e.Item.FindControl("hidID")).Value);
                        string subject = ((TextBox)e.Item.FindControl("txtSubject")).Text;
                        string text = ((FCKeditor)e.Item.FindControl("FCKeditor1")).Value;
                        DiaryData.SaveDiaryNote(id, subject, text);
                        lstCalendarNotes.EditItemIndex = -1;
                        SetCalendarNotes();
                        break;
                    }

                case "Cancel":
                    lstCalendarNotes.EditItemIndex = -1;
                    SetCalendarNotes();
                    break;
            }

        }

    Any help greatly appreciated!

     Simon
     

    Tuesday, June 26, 2007 5:22 AM
  • User-2063076121 posted

    That's probably because javascript incontrols wont run on partial postback. On the clent you need some javascript to handle the update success event and tell the fckeditor to update itself. Look into the PageRequestManager (or something similiar) in the ajax client-side docs.

    Tuesday, June 26, 2007 11:42 AM
  • User-565895123 posted

     Thanks for the pointer Josh, will look into it and report back any solution.

     

    Cheers 

    Tuesday, June 26, 2007 7:39 PM
  • User-2070978840 posted

    Any updates on this?  It doesn't seem like we've found a universal solution yet. It would be nice to have something built into the .net control or fckeditor itself that would handle this.

    I see that there is a bug posted for this: http://dev.fckeditor.net/ticket/234. Hopefully they will fix it.

    Wednesday, July 18, 2007 2:24 PM
  • User1922708436 posted
    This solutions you all posted no longer work in VS2008 Orcas Beta2. Can someone in the know look into this to identify who is at fault, FCK Editor or Microsoft? If Microsoft introduced a bug, we need to inform them ASAP so it s fixed in the final product.

    Please see
    <!-- l -->http://forums.asp.net/p/1142645/1841899.aspx#1841899<!-- l -->
    for details.

    Thanks!

    Sunday, August 5, 2007 12:50 PM
  • User1922708436 posted

    Also see this:

     http://www.fckeditor.net/forums/viewtopic.php?f=6&t=6454
     

    Tuesday, September 25, 2007 9:57 PM
  • User1786282994 posted

    This still isn't solved.... anyone get anywhere on this?

    The issue in question is javascript error in FF:

    "FCK is not defined"
     

    Wednesday, December 12, 2007 9:19 AM
  • User-2070978840 posted

    I've given up on fckeditor in asp.net. Every time a new version of AJAX or FCKEditor comes out it seems to break in a different way. I'm waiting until the FCKEditor crew finally updates their asp.net control to address these problems.

    Wednesday, December 12, 2007 12:44 PM
  • User1922708436 posted

     The last post in this thread:

     http://www.fckeditor.net/forums/viewtopic.php?f=6&t=6454

     solved this problem for me.  I have not tried this with the latest release of fckEditor however.
     

    Wednesday, December 12, 2007 6:42 PM
  • User1392226401 posted

    Hi all,
    Thank you josh for your post. but we cannot use UpdatePanel feature to not to refresh the page. How can we solve this problem?
    any solutions?

    Tuesday, February 26, 2008 4:10 AM
  • User-12650050 posted

     I was trying to use FCKEditor in a Custom control and then use this custom control in a updatepanel... i had problems and bugs as you can imagine.

     So, i used the solution provided by Josh and add some stuff this way in the Pre_Render event where "fckWriteContent" is my FCKEditor instance:

     

    1    Page.ClientScript.RegisterOnSubmitStatement(fckWriteContent.GetType(),
    2                                                                "editor",
    3                                                                "FCKUpdateLinkedField('" + fckWriteContent.ClientID + "');");
    4    
    5                ScriptManager current = ScriptManager.GetCurrent(this.Page);
    6    
    7                String script = @"function FCKUpdateLinkedField(id)
    8                                    {
    9                                        try
    10                                       {
    11                                           if(typeof(FCKeditorAPI) == 'object')
    12                                           {
    13                                               FCKeditorAPI.GetInstance(id).UpdateLinkedField();
    14                                           }
    15                                       }
    16                                       catch(err)
    17                                       {
    18                                       }
    19                                   }";
    20                   if (current != null)
    21                   {
    22   
    23                       ScriptManager.RegisterClientScriptBlock(this,
    24                                                               typeof(Page),
    25                                                               "FCKUpdateLinkedField",
    26                                                               script,
    27                                                               true);
    28                   }
    29                   else
    30                   {
    31                       Page.ClientScript.RegisterClientScriptBlock(typeof(Page),
    32                                                                   "FCKUpdateLinkedField", 
    33                                                                   script, 
    34                                                                   true);
    35                   }
    

     

    and everything worked like a charm...

    thanks Josh...!!!

     

    HTH


     

    Wednesday, February 27, 2008 12:18 PM
  • User-1403527637 posted

    Pichto solution didn't work for me until I did something "stupid".

     

    My FckEditor is inside a Div that I hide with style="display: none"/style="display: block" depending of the situation. I was getting the error FCK editor is not defined after trying to submit the form with validation errors - to check that the validation errors where firing. Even when the DIV was being displayed.

     

    The solution is to have the PICHTO fix AND make the FCKeditor.visible property set to False when the div is not visible and FCKeditor.visible property to true when it becomes visible inside the div. This seems to fix it somehow.

     
    ========

    when FCKEditor is hidden remember to do this: 

    FCKEditor.visible=false

     

    when FCKEditor is displayed remember to do this:

     

    FCKEditor.visible=true

    =======
     

     

    I still have a problem, the AJAX validation extender stops firing (it only validates 1 field, and not the other 2 I have left to validate) but this might have nothing to do with this javascript error....

     

    Tuesday, March 11, 2008 6:03 AM
  • User-12650050 posted

     I all,

     I've made a change to my solution as i had problems with multiple FCKeditors in different (or same) updatepanels on the same page (up to 18 in fact).

     
    So, here is my final solution :

     

     

    protected override void OnPreRender(EventArgs e)
    {
    if (!this.Page.IsPostBack)
    {

    ScriptManager current = ScriptManager.GetCurrent(this.Page);

    String script = @"function FCKUpdateLinkedField(id)
    {
    try
    {
    if(typeof(FCKeditorAPI) == 'object')
    {
    FCKeditorAPI.GetInstance(id).UpdateLinkedField();
    }
    }
    catch(err)
    {
    }
    }"
    ;
    if (current != null)
    {

    ScriptManager.RegisterClientScriptBlock(this,
    typeof(WebContentManager),
    "FCKUpdater",
    script,
    true);

    ScriptManager.RegisterOnSubmitStatement(this,
    typeof(WebContentManager),
    "WebContentManagerEditorScript_" + this.fckWriteContent.ClientID,
    "FCKUpdateLinkedField('" + this.fckWriteContent.ClientID + "');");
    }
    else
    {
    Page.ClientScript.RegisterClientScriptBlock(typeof(WebContentManager),
    "FCKUpdater",
    script,
    true);

    this.Page.ClientScript.RegisterOnSubmitStatement(typeof(WebContentManager),
    "WebContentManagerEditorScript_" + this.fckWriteContent.ClientID,
    "FCKUpdateLinkedField('" + this.fckWriteContent.ClientID + "');");
    }
    }

    base.OnPreRender(e);
    }

     

     where WebContentManager is my user control which displays or not a FCKEditor, where fckWriteContent is the instance of my FCKEditor.

     The change is basically in the "RegisterOnSubmitStatement" where i use

    "WebContentManagerEditorScript_" + this.fckWriteContent.ClientID,
    to tell the server to register the javascript statement for each FCKEditor on the page and not only for the first one. Note also the use of !Page.IsPostBack to tell the server to register all those scripts only once and not everytime we post!
     
    HTH 

     

     

    Tuesday, March 11, 2008 12:39 PM
  • User-441552307 posted

     does this work for everyone ?

    I still got the problem... [:(]

     

    my code is as following (I got 2 editors in the same update panel):

      

    1    protected override void OnPreRender(EventArgs e)
    2        {
    3            if (!this.Page.IsPostBack)
    4            {
    5    
    6                ScriptManager current = ScriptManager.GetCurrent(this.Page);
    7    
    8                String script = @"function FCKUpdateLinkedField(id)
    9                                    {
    10                                       try
    11                                       {
    12                                           if(typeof(FCKeditorAPI) == 'object')
    13                                           {
    14                                               FCKeditorAPI.GetInstance(id).UpdateLinkedField();
    15                                           }
    16                                       }
    17                                       catch(err)
    18                                       {
    19                                       }
    20                                   }";
    21               if (current != null)
    22               {
    23   
    24                   ScriptManager.RegisterClientScriptBlock(this,
    25                                                           typeof(_CMS),
    26                                                           "FCKUpdater",
    27                                                           script,
    28                                                           true);
    29   
    30                   ScriptManager.RegisterOnSubmitStatement(this,
    31                                                           typeof(_CMS),
    32                                                           "WebContentManagerEditorScript_" + this.FCKeditorText1.ClientID,
    33                                                           "FCKUpdateLinkedField('" + this.FCKeditorText1.ClientID + "');");
    34   
    35                   ScriptManager.RegisterOnSubmitStatement(this,
    36                                                           typeof(_CMS),
    37                                                           "WebContentManagerEditorScript_" + this.FCKeditorText2.ClientID,
    38                                                           "FCKUpdateLinkedField('" + this.FCKeditorText2.ClientID + "');");
    39               }
    40               else
    41               {
    42                   Page.ClientScript.RegisterClientScriptBlock(typeof(_CMS),
    43                                                               "FCKUpdater",
    44                                                               script,
    45                                                               true);
    46   
    47                   this.Page.ClientScript.RegisterOnSubmitStatement(typeof(_CMS),
    48                                                          "WebContentManagerEditorScript_" + this.FCKeditorText1.ClientID,
    49                                                           "FCKUpdateLinkedField('" + this.FCKeditorText1.ClientID + "');");
    50   
    51                   this.Page.ClientScript.RegisterOnSubmitStatement(typeof(_CMS),
    52                                                          "WebContentManagerEditorScript_" + this.FCKeditorText2.ClientID,
    53                                                           "FCKUpdateLinkedField('" + this.FCKeditorText2.ClientID + "');");
    54               }
    55           }
    56   
    57           base.OnPreRender(e);
    58       }
    
     
     
    Tuesday, March 11, 2008 5:20 PM
  • User860824526 posted

     I fixed the FCKEditor and you can download my fix here

    Thanks,

     Tyler Garlick
     

    Monday, April 14, 2008 11:14 PM
  • User1062417797 posted

    Hi,

    I can see this is a pretty old post. Incredible that the same error still exists. I'm using the FCKEditor inside a GridView which is inside an updatepanel (amongst others like Multiview, View, etc..). The Solution you presented doesn't seem to work for me. Here some of the Code I've written. Anyone got a clue to why this is not working? I'm trying to get it working with the Standard 'Edit' button.

    Paul 

      

    ...

    <asp:GridView ID="gvComment" runat="server"
    AutoGenerateColumns="False"
    DataKeyNames="CommentID,ForeignKey,ForeignTopic"
    AllowPaging="True"
    AllowSorting="True"
    CssClass="gridview"
    DataSourceID="dsComment"
    AutoGenerateDeleteButton="True"
    AutoGenerateEditButton="True" >
    <Columns>
    <asp:TemplateField HeaderText="Text" SortExpression="Text">
    <EditItemTemplate>
    <FCKeditorV2:FCKeditor ID="fckCommentEditor" runat="server"
    BasePath="fckeditor/"
    Value='<%# Bind("Text") %>'
    OnLoad="fckCommentEditor_Load" >
    </FCKeditorV2:FCKeditor>
    </EditItemTemplate>
    <asp:GridView id="<span" class="st"><Columns><asp:TemplateField headertext="<span" class="st"><EditItemTemplate><FCKeditorV2:FCKeditor id="<span" class="st"> </FCKeditorV2:FCKeditor>
    </EditItemTemplate>


    ...


    <script language="<span" class="st">"javascript" type="text/javascript"> function FCKUpdateLinkedField(id) { try { if(typeof(FCKeditorAPI) == "object") { FCKeditorAPI.GetInstance(id).UpdateLinkedField(); } } catch(err) { } } </script>

    ...

    private void CreateFCKWorkarround(object sender)
    {
    FCKeditor fe = (FCKeditor)sender;
    ClientScriptManager csm = Page.ClientScript;
    Type feType = fe.GetType();
    string strName = "wa_fckeditor";

    if (fe != null)
    {
    if (!csm.IsOnSubmitStatementRegistered(feType, strName))
    {
    csm.RegisterOnSubmitStatement(feType, strName,
    "FCKUpdateLinkedField('" + fe.ClientID + "');");
    }
    }
    }

    protected void fckCommentEditor_Load(object sender, EventArgs e)
    {
    CreateFCKWorkarround(sender);
    }
    </asp:TemplateField></Columns></asp:GridView>
     

     

    Thursday, May 29, 2008 5:43 AM
  • User1922708436 posted

    Paul,

     

    Save yourself a lot of headache and time and use Telerik's editor instead of FCK.  FCK is not widely used on the .NET platform and therefore you will run into problem after problem.  Telerik's solution was built on Microsoft Ajax (Atlas) and seems better suited for the ASP.NET world. 

    Thursday, May 29, 2008 6:08 PM
  • User1062417797 posted

    Spending $999 is not what I have in mind at the moment. Telerik may (or may not) have solved the problems I currently experience. No seriously, I am still at it and I have set my mind to solving this. So if anyone has some (constructive) pointers I am all ears.

     

    Thursday, June 5, 2008 4:41 PM
  • User123359115 posted

    Thanks for sharing the solution. It worked at first attemp!

    Thanks again.

    Thursday, June 5, 2008 6:55 PM
  • User1062417797 posted

    Eureka! I finally got it working too. My first attempt was in the wront PreRender. I put it in the PreRender of my Web User Control but that was wrong of course. I've now put it in the PreRender of the FCKEditor Control and it works (pfew.. got time after more than a week of struggling). To be complete I posted the code of my Control Below.

      

    <%@ Control Language="C#" AutoEventWireup="false" CodeFile="CEditor.ascx.cs" Inherits="Controls_CEditor" %>
    <%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="WebLogFCKeditorV2" %>
    
    <asp:Panel runat="server" id="pnlEditorPanel" CssClass="DropShadowPanel"
                style="width:610px; height:410px; padding: 5px;" >
        <WebLogFCKeditorV2:FCKeditor ID="edtEditor" runat="server" 
                                        BasePath="fckeditor/"
                                        Width="600px" Height="400px"
                                        EnableViewState="true"
                                        OnPreRender="edtEditor_PreRender" />
    </asp:Panel>
    

      

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using MyLibrary.Common;
    
    public partial class Controls_CEditor : System.Web.UI.UserControl
    {
        private const string cstrEditorViewState = "EditorViewState";
    
        public string Text
        {
            get
            {
                return CHTML.HTMLToString(edtEditor.Value);
            }
            set
            {
                edtEditor.Value = CHTML.StringToHTML(value);
            }
        }
    
        protected void edtEditor_PreRender(object sender, EventArgs e)
        {
            ScriptManager current = ScriptManager.GetCurrent(this.Page);
    
            String script = @"function FCKUpdateLinkedField(id)
                                {
                                    try
                                    {
                                        if(typeof(FCKeditorAPI) == 'object')
                                        {
                                            FCKeditorAPI.GetInstance(id).UpdateLinkedField();
                                        }
                                    }
                                    catch(err)
                                    {
                                    }
                                }";
    
            if (current != null)
            {
                ScriptManager.RegisterClientScriptBlock(this,
                                                        typeof(Controls_CEditor),
                                                        "FCKUpdater",
                                                        script,
                                                        true);
                ScriptManager.RegisterOnSubmitStatement(this,
                                                        typeof(Controls_CEditor),
                                                        "WebContentManagerEditorScript_" + this.edtEditor.ClientID,
                                                        "FCKUpdateLinkedField('" + this.edtEditor.ClientID + "');");
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(typeof(Controls_CEditor),
                                                            "FCKUpdater",
                                                            script,
                                                            true);
    
                this.Page.ClientScript.RegisterOnSubmitStatement(typeof(Controls_CEditor),
                                                                 "WebContentManagerEditorScript_" + this.edtEditor.ClientID,
                                                                 "FCKUpdateLinkedField('" + this.edtEditor.ClientID + "');");
            }
        }
    }
    
    The CHTML Class changes the HTML to String and Vice Versa like this:
     
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace MyLibrary.Common
    {
        public class CHTML
        {
            private const string cstrTransLessThen      = "#LS#";
            private const string cstrTransGreaterThen   = "#GT#";
    
            public static string StringToHTML(string pstrString)
            {
                return pstrString.Replace(cstrTransGreaterThen, "&gt;").Replace(cstrTransLessThen, "&lt;");
            }
    
            public static string HTMLToString(string pstrHTML)
            {
                return pstrHTML.Replace("&gt;", cstrTransGreaterThen).Replace("&lt;", cstrTransLessThen);
            }
        }
    }
    
     

    Thanks all for sharing this info.

    Cheers,
    Paul.

    Friday, June 6, 2008 8:08 AM
  • User2094277065 posted

    Very thanks man!
    this solution worked very well!!!

    Thanks [Yes]

    Friday, June 6, 2008 1:52 PM
  • User1062417797 posted

    Hi All,

     Made a little change to the code. The superfluous Property 'EditorText' has been removed.

    Another remark I must make: The interface of this Forum changed the characters 'Less than' and 'Greater than' into '&ls;' and '&gt;'. They should be the characters!!!!

    Cheers,
    Paul.

    Sunday, June 8, 2008 6:06 AM
  • User1062417797 posted

    Hi All,

     I've created a new class that derives from the FCKeditor Class. A description can be found on the FCKeditor Forum

    http://www.fckeditor.net/forums/viewtopic.php?f=6&t=9826&p=26287#p26287

    Cheers,
    Paul

    Sunday, June 8, 2008 10:37 AM
  • User-1827083345 posted

    There are already dedicated tickets on fckeditor's bugtracker for the two issues described here. See the following links:

    http://dev.fckeditor.net/ticket/234

    http://dev.fckeditor.net/ticket/1255 

    I've provided there an AJAX-compatible version of the original FCKeditor.NET control. You can download this as an attachment from the above bug tickets.

    It inherits from the existing control, and implements IScriptControl to embed client-side functionality. So with this fix you need to make no modifications to your own code. You can use the new control on the page just like the non-AJAX version, only this works inside an UpdatePanel. I consider this a neater implementation than anything else described here, since it properly leverages the AJAX framework to transparently implement the client-side behaviour.

    Please see the comments on the bug ticket for further information about the cause of the problem, and implementation details.

    There are still some minor problems encountered beyond the "FCK is not defined" Firefox error. These further errors are linked to the FCK core, which I'm still working on a fix for. These errors do not prevent the editor working, but they could result eventually in memory leakage or other unwanted effects.

    If possible, please bring any further discussion of this problem directly to the FCK bug tracker (after first reading all the comments there of course ;).

    Edit: I've just had a new look at the ticket (#1255) and realised I never posted my patch. I had to modify FCK's core to fix the Firefox error. If anyone needs this patch urgently I can provide it, but I probably won't submit it to the bug ticket until I've eliminated the further errors I described above.


    Tuesday, June 17, 2008 9:19 AM
  • User445259773 posted

    I find I'm getting the same error "FCK is not defined" using the pached files and the ajax compatable version. The difference might be I'm using master pages? Also when I include 2 of these controls inside an update panel I get a post back. If I remove them and submit no post back? Thanks for your effort but for me it stills seems to be borked.

    Thursday, July 10, 2008 3:19 PM
  • User-51021203 posted

     

    private void Page_Load(object sender, EventArgs args)
    {
    Page.ClientScript.RegisterOnSubmitStatement(editor.GetType(), "editor",
        "FCKUpdate('" + editor.ClientID + "');");
    }
    function FCKUpdate(id)
    {
    if(typeof(FCKeditorAPI) == "object")
    {
    FCKeditorAPI.GetInstance(id).UpdateLinkedField();
    }

    }
    Wednesday, March 4, 2009 6:43 AM
  • User-992621826 posted

     A very very simple solution of this problem is - just write the below single line code to your Page_Load(). It'll work for multiple FCK Editor present inside update panel also.

     

    this.Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "AjaxHack", "for ( var i = 0; i < parent.frames.length; ++i ) if ( parent.frames[i].FCK ) parent.frames[i].FCK.UpdateLinkedField();");

     

    Happy Coding

    Saturday, June 13, 2009 4:44 AM
  • User-1614003617 posted

    I made a minor tweak to ajitsatpathy's code (converted to VB.NET, used ScriptManager instead of Page.ClientScript) and it worked for me

     

    ScriptManager.RegisterOnSubmitStatement(Me, Me.GetType(), "AjaxHack", "for ( var i = 0; i < parent.frames.length; ++i ) if ( parent.frames[i].FCK ) parent.frames[i].FCK.UpdateLinkedField();")


     

    Thursday, September 10, 2009 11:04 AM