首页 > 解决方案 > .Net jQuery WYSIWYG 隐藏在 AJAX 回发上

问题描述

我在我的 .Net 应用程序中使用 WYSIWYG 编辑器 Summernote。当我使用 AJAX 回发时,表单工作正常,但是所见即所得消失了。我收集我需要再次运行初始化程序。我正在使用下面的代码来尝试。

<script>
$('#<%=txtDescription.ClientID%>').summernote({
    tabsize: 2,
    height: 100,
    toolbar: [
        ['style', ['bold', 'italic', 'underline']],
        ['color', ['color']],
        ['para', ['ol', 'paragraph']],
        ['insert', ['link', 'picture', 'video', 'table', 'hr']]
    ]
});

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function (s, e) {
    $('#<%=txtDescription.ClientID%>').summernote({
        tabsize: 2,
        height: 100,
        toolbar: [
            ['style', ['bold', 'italic', 'underline']],
            ['color', ['color']],
            ['para', ['ol', 'paragraph']],
            ['insert', ['link', 'picture', 'video', 'table', 'hr']]
        ]
    });
});

它没有重新加载编辑器,我收到错误:

Uncaught TypeError: $(...).summernote is not a function at Array.....

Chrome 中的错误文本

标签: c#jquery.netajax

解决方案


我认为主要问题是我的 jQuery 和 Bootstrap 引用不准确。下面的代码最终起作用了。

function pageLoad() { // this gets fired when the UpdatePanel.Update() completes
                            $('#<%=txtDescription.ClientID%>').summernote({
                                tabsize: 2,
                                height: 100,
                                toolbar: [
                                    ['style', ['bold', 'italic', 'underline']],
                                    ['color', ['color']],
                                    ['para', ['ol', 'paragraph']],
                                    ['insert', ['link', 'picture', 'video', 'table', 'hr']]
                                ]
                            });
                        }

推荐阅读