Search code examples
ckeditorcode-behinddata-retrieval

How to retrieve data of CKEditor in code behind of an aspx page


I'm trying to integrate CKEditor with my application and I'm using the below approach.

<textarea name="editor1" id="editor1" rows="10" cols="80"></textarea>
<script type="text/javascript">
    CKEDITOR.replace('editor1');
</script>

and in JavaScript to set and get data to ckeditor I'm using the code as below

function cksetdata(val)
        {
           CKEDITOR.instances.editor1.setData(val);
       }
var data = CKEDITOR.instances.editor1.getData();

It is working perfect when using JavaScript.

but I want to set and get data from code behind as I want to save the data of CKEditor into database.

If using the CKEditor as control in aspx page I'm able to retrieve data by using .Text property of CKEditor, but unable to get data through JavaScript.

I need to retrieve data from both JavaScript and codebehind.


Solution

  • Thanks for ur answer Mr.Raymond kuipers..

    Im using a work around for this problem..

    As im able to retrieve data in javascript im assigning that data to a hidden variable and accessing the value of that hidden variable in my button save event..

        function getCkEditordata() {
        document.getElementById('<%=hdn1.ClientID%>').value = CKEDITOR.instances.editor1.getData();
        alert(document.getElementById('<%=hdn1.ClientID%>').value);
    }
    

    in this way assigning to a hidden variable and accessing that data in code behind as follows..

    String templatecontent =  hdn1.Value;