我想在更新面板中为文本区域使用富文本编辑器.
我发现这篇帖子:http://www.queness.com/post/212/10-jquery-and-non-jquery-javascript-rich-text-editors通过这个问题:需要ASP.Net/MVC富文本编辑器
决定使用TinyMCE,因为我之前在非AJAX情况下使用它,并且它在该列表中说它与AJAX兼容.好吧,我做了很好的' tinyMCE.init({ //settings here });
测试它,它在更新面板更新后消失了.我从这里的一个问题中找出它应该在page_load函数中,所以它甚至可以在异步回发上运行.好吧,这样做,面板停留.但是,在尝试从我的textarea提交值时,它的文本总是返回为空,因为我的表单验证器总是说"你必须输入描述",即使我在其中输入文本.这是在页面第一次加载以及对页面执行异步回发之后发生的.
好吧,我发现这个http://www.dallasjclark.com/using-tinymce-with-ajax/并且不能从同一个AJAX TinyMCE textarea发布两次.我尝试在tinyMCE.init之后立即将此代码添加到我的页面加载函数中.这样做会破坏我之后在page_load中调用的所有jquery,它仍然存在同样的问题.
我仍然是客户端脚本编写的初学者,所以也许我需要将代码放在与page_load不同的位置?不确定我链接的帖子不知道放置代码的位置.
我的Javascript:
<script type="text/javascript">
var redirectUrl = '<%= redirectUrl %>';
function pageLoad() {
tinyMCE.init({
mode: "exact",
elements: "ctl00_mainContent_tbDescription",
theme: "advanced",
plugins: "table,advhr,advimage,iespell,insertdatetime,preview,searchreplace,print,contextmenu,paste,fullscreen",
theme_advanced_buttons1_add_before: "preview,separator",
theme_advanced_buttons1: "bold,italic,underline,separator,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink,separator,styleselect,formatselect",
theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,separator,removeformat,cleanup,charmap,search,replace,separator,iespell,code,fullscreen",
theme_advanced_buttons2_add_before: "",
theme_advanced_buttons3: "",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
extended_valid_elements: "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
paste_auto_cleanup_on_paste: true,
paste_convert_headers_to_strong: true,
button_tile_map: true
});
tinyMCE.triggerSave(false, true);
tiny_mce_editor = tinyMCE.get('ctl00_mainContent_tbDescription');
var newData = tiny_mce_editor.getContent();
tinyMCE.execCommand('mceRemoveControl', false, 'your_textarea_name'); …Run Code Online (Sandbox Code Playgroud) 当我单击一个导致回发的按钮时,UpdatePanel它会调用tinyMCE.triggerSave().
它重新加载面板并且编辑器再次出现,但是当我tinyMCE.triggerSave()第二次尝试调用时出现以下错误:
g.win.document is null
Run Code Online (Sandbox Code Playgroud)
我虽然得到了旧的实例,但是tinyMCE.execCommand('mceRemoveControl',false,'Editor');在调用save之后我也删除了control().即便如此,它仍然第二次崩溃.
我该如何解决?