Question

i'm using nicedit.js to convert my textarea to html editor, when i call the directly the page there is no prob, but when i call via ajax call, or call page which under jquery tab, the editor page not load but pop error,

Error: 'null' is null or not an object

i declare my textarea as below

bkLib.onDomLoaded(function() {
    new nicEditor({iconsPath :'<%=request.getContextPath()%>/images/nicEditorIcons.gif',
    maxHeight:345,
    buttonList : ['save','bold','italic','underline','left','center','right','justify','ol','ul','fontSize','fontFamily','fontFormat','indent','outdent','image','upload','link','unlink','forecolor','xhtml']}).panelInstance('content');
});

anyone has use nicedit with ajax

thanks in advance

Was it helpful?

Solution

after cracking my head, finally i found solution, so when ever call page which contain editor via ajax, just declare the textarea as new nicEditor().panelInstance('content');

not bkLib.onDomLoaded(function() { new nicEditor().panelInstance('content'); }

OTHER TIPS

I use

new nicEditors.allTextAreas;

instead of

bkLib.onDomLoaded(nicEditors.allTextAreas);

Basically if you are working with ASP.NET and Update Panel you can copy-paste the code. NOTE: Don't forget to change the textarea Ids for yours.

    <script type="text/javascript">


    //hdnNicEdit: it is a hiddenfield in ASP page.
    function SaveContent() {
        $("#<%=hdnNicEdit.ClientID %>").val($(".nicEdit-main").html());
    }


    function pageLoad() {
        $(function () {

            new nicEditor().panelInstance('here your textarea id');
            $(".nicEdit-main").html($("#<%=hdnNicEdit.ClientID %>").val());




        })
    } 

</script>

ASP PAGE:

        <textarea ID="YOUR TEXTAREA ID" class="form-control" runat="server"></textarea>
        <asp:HiddenField ID="hdnNicEdit" runat="server" />

NOTE: you need to add: OnClientClick="SaveContent();" into the button where you save the nicedit textarea value.

SERVER SIDE.

Getting text area value:

  string textAreaValue = hdnNicEdit.value;

Setting textarea value:

hdnNicEdit.value = "i am setting text into textarea"

More info: https://dotnetdaily.net/web-development/tutorials/aspdotnet/nicedit-work-update-panel-asp-net

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top