2013-04-22 57 views
0

我目前正在尋找一種方式使用C# 我已經在網上看到使用jQuery的例子將數據加載到CKEDITOR的實例,但我需要它的C#C#加載默認數據爲CKEDITOR

我CKEditor的長相像這樣:

<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> 

,我使用此代碼在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); 
    } 

我知道加載js文件,並保存在塊中的任何文字,但我怎麼設置默認DA ta在說塊?

我試過正常

txtArt.Text = "Hello"; 

,但不起作用。 它加載空字段。 有沒有辦法像How to add data to CKEditor using JQuery那樣做? 或How to load data into ckeditor onload

請注意,我試圖從數據庫加載數據。所以我在.cs頁面上的代碼是我需要加載的代碼。

+0

您是否使用沒有.Net控件的CKEditor for ASP.NET或CkEditor標準? – 2013-04-22 15:15:23

回答

2

如果您使用的是CKEditor for ASP.NET,它具有ASP.NET控件以便於集成。在身體

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

,並在頁面加載或按鈕點擊功能背後的代碼設置類的編輯器的內容

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

和地方的編輯控制:您可以如下注冊。

CKEditor1.Text = "This is the text I want to set in CKEDITOR"; 
+0

啊!謝謝。我有另一個版本。下載asp.net版本並立即使用 – 2013-04-23 05:48:22