0

I am currently looking for a way to load data into an instance of CKEDITOR using C# the examples I've seen online use jquery, but I need it for c#

my ckeditor looks like so:

<asp:TextBox ID="txtArt" runat="server" ></asp:TextBox>

    <script>
        CKEDITOR.replace('<%=txtArt.ClientID %>', {
            htmlEncodeOutput: false,
            height: '400px',
            width: '500px',
            resize_enabled: false,
            removePlugins: 'elementspath'
        });
</script>

and I'm using this code in c#:

        public String Value
    {
        get
        {
            EnsureChildControls();
            return txtArt.Text;
        }
        set
        {
            EnsureChildControls();
            txtArt.Text = value;
        }
    }
    protected override void OnInit(EventArgs e)
    {
        if (!Page.ClientScript.IsClientScriptIncludeRegistered("ckeditor.js"))
        {
            Page.ClientScript.RegisterClientScriptInclude("ckeditor.js", "/ckeditor/ckeditor.js");
        }
        base.OnInit(e);
    }

I know that loads the js file, and will save any text in the block, but how do I set default data in said block?

I've tried the normal

txtArt.Text = "Hello";

but that doesn't work. it loads up with empty fields. is there a way to do something like How to add data to CKEditor using JQuery ? or How to load data into ckeditor onload ?

Please be advised, I'm trying to load data from a database. so my code on the .cs page is the code I need for the loading.

4

1 回答 1

3

If you are using CKEditor for ASP.NET it has the ASP.NET Control for easy integration. and you can register it as below:

<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>

and place editor control in the body

<form id="form1" runat="server">
   <div>
     <CKEditor:CKEditorControl ID="CKEditor1" BasePath="/ckeditor/" runat="server"></CKEditor:CKEditorControl>
   </div>
</form>

and in the code behind on page load or button click function set the content of editor like.

  CKEditor1.Text = "This is the text I want to set in CKEDITOR";
于 2013-04-22T15:14:33.050 回答