简体   繁体   English

UpdatePanel initializeRequest控制值是否为时已晚?

[英]UpdatePanel initializeRequest Control Values Too Late To Change?

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. 面板加载后,CKEditor将应用于文本区域。 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. 问题在于UpdatePanel并非总是通过该按钮触发,有时它是远程触发的。 It seems that by the time initializeRequest is called, the value for the textarea is already set. 似乎在调用initializeRequest时,已经设置了textarea的值。 Is there a way to update that value at this point? 现在有没有办法更新该值?

The answer: forget CKEditor, tinyMCE, and all the other rich text editors if you're using .NET. 答案:如果您使用的是.NET,请忘记CKEditor,tinyMCE和所有其他富文本编辑器。 I can't believe it took me so long to find out about the AJAX Control Toolkit . 我不敢相信我花了这么长时间才了解AJAX控制工具包

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM