UpdatePanel initializeRequest Control Values Too Late To Change?

264 Views Asked by At

Here is my code:

<asp:UpdatePanel ID="up1" runat="server">
    <ContentTemplate>
        <script type="text/javascript">
            var app = Sys.WebForms.PageRequestManager.getInstance();
            app.add_pageLoaded(createEditor)
            app.add_initializeRequest(removeEditor)

            function createEditor() {
                if (editor) return;
                var config = { toolbar: 'Description', width: 540 };
                editor = CKEDITOR.replace("editor", config);
            }

            function removeEditor() {
                if (!editor) return;
                editor.destroy();
                editor = null;
            }
        </script>

        <textarea id="editor" cols="1" rows="1" runat="server">
        </textarea>

        <asp:Button ID="btnsubmit" Text="Get 'er Done" runat="server" />
        <div>
            <%=strmessage%>
        </div> 
    </ContentTemplate>
</asp:UpdatePanel>

When the panel loads, the CKEditor is applied to the textarea. When the panel posts back, the editor must be destroyed to put the data back into the textarea. In this code, the Editor is not destroyed in time to update the postback data. It works if I do this:

<asp:Button ID="btnsubmit" onClientClick="removeEditor()" Text="Get 'er Done"
   runat="server" />

The problem is the UpdatePanel is not always triggered with that button, sometimes it's triggered remotely. It seems that by the time initializeRequest is called, the value for the textarea is already set. Is there a way to update that value at this point?

1

There are 1 best solutions below

0
On

The answer: forget CKEditor, tinyMCE, and all the other rich text editors if you're using .NET. I can't believe it took me so long to find out about the AJAX Control Toolkit.