Thursday, December 9, 2010

FCK Editor not working with Update Panel

There is compatibility issue of FCK Editor with Update Panel, because both use AJAX plugin. To run it properly we need to register FCK Editor on page load.

function WebForm_OnSubmit()
{
for ( var i = 0; i < parent.frames.length; ++i ) if ( parent.frames[i].FCK ) parent.frames[i].FCK.UpdateLinkedField(); (function() { var editor = FCKeditorAPI.GetInstance('master_Content1_fckEditor1'); if (editor) editor.UpdateLinkedField(); })(); return true; }


But problem is that, if we have multiple number of FCK Editor, then we have to register all FCK Editor. To solve this issue, I discovered a simple C# code, which will find all FCK Editor present inside Update Panel & register them all automatically.

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FCKEditor();
}
}
private void FCKEditor()
{
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!!!