2013-02-23 72 views
1

我已將CKEditor.Net添加到我的ASP.NET Web應用程序項目中。當我嘗試文本使用JavaScript,它給這個錯誤CKEditor未定義

Error: 'CKEDITOR' is undefined 

這是我的代碼插入,

HTML

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="eLetters.Test" %> 
<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"> 
    <script type="text/javascript"> 
     function insertText(text) { 
      CKEDITOR.instances.insertText('text'); 
     } 
    </script> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server"> 
</asp:Content> 
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server"> 
    <CKEditor:CKEditorControl ID="CKEditor1" BasePath="/ckeditor/" runat="server"></CKEditor:CKEditorControl> 
</asp:Content> 

C#

protected void Button1_Click(object sender, EventArgs e) 
    { 
     Page.ClientScript.RegisterStartupScript(GetType(), "MyKey", "insertText('data');", true); 
    } 

什麼時我在這裏做錯了嗎?

+0

你到底想幹什麼?設置默認內容? – MikeSmithDev 2013-02-23 02:39:51

+0

@MikeSmithDev我需要做的是,從按鈕點擊插入一些文本到CKEditor:http://stackoverflow.com/questions/15018700/insert-text-to-ckeditor-programtically – Nalaka526 2013-02-23 03:57:23

回答

0

嘗試在您的標記中設置BasePath="~/ckeditor"

這裏有一個代碼隱藏片斷實例化工具欄:

CKEditor1.config.toolbar = new object[] 
{ 
    new object[] { "Bold", "Italic", "Underline", "Strike", "-", "Cut", 
    "Copy", "Paste", "PasteText", "-", "NumberedList", "BulletedList", 
    "-", "Outdent", "Indent", "Blockquote", "-", "JustifyLeft", 
    "JustifyCenter", "JustifyRight", "JustifyBlock"} }; 

評論你的文本插入腳本,只是把它設置爲開始;-)

+1

其實CKEditor在我的項目中工作正常,但是當我嘗試從JavaScript插入文本,它給出了錯誤... – Nalaka526 2013-02-23 04:00:35

+0

@ Nalaka526你是正確的,但你的Javascript是在錯誤的地方,並沒有做任何插入一個特定的索引。 – MikeSmithDev 2013-02-23 04:55:19

+0

@MikeSmithDev我將javascript調用代碼從'PageLoad'移動到'ButtonClick',所以它有一個光標位置來插入文本。我要在哪裏移動JavaScript? – Nalaka526 2013-02-23 06:32:15

相關問題