|
引用js
<script language="Javascript" type="text/Javascript" src='<%=ResolveUrl("~/ckeditor/ckeditor.js")%>'></script>
3.添加一個編輯框
<ASP:TextBox ID="mckeditor" runat="server" TextMode="MultiLine"></ASP:TextBox>
4.在下面添加如下代碼
復(fù)制代碼 代碼如下:
<script type="text/Javascript">
//<![CDATA[
CKEDITOR.replace( '<%=mckeditor.ClientID %>',// mckeditor.ClientID為TextBox mckeditor生成的對應(yīng)客戶端看到的id
{
skin : 'office2003',//設(shè)置皮膚
enterMode : Number( 2),//設(shè)置enter鍵的輸入1.<p>2為<br/>3為<div>
shiftEnterMode : Number( 1), // 設(shè)置shiftenter的輸入
});
//]]>
</script>
像上面這樣就可以完成基本的功能了,但是有的時候我們要上傳文件,cfeditor的文件功能是通過插件實(shí)現(xiàn)的,下面介紹文件插件的CKFinder的配置
1. 到http://www.ckfinder.com/下載插件(主意選擇ASP.NET版的),放到網(wǎng)站目錄下
2. 在之前的ckeditor配置信息后面添加如下代碼
復(fù)制代碼 代碼如下:
filebrowserBrowseUrl:'<%=ResolveUrl("~/ckfinder/ckfinder.html")%>',
filebrowserImageBrowseUrl:'<%=ResolveUrl("~/ckfinder/ckfinder.html?Type=Images")%>',
filebrowserFlashBrowseUrl:'<%=ResolveUrl("~/ckfinder/ckfinder.html?Type=Flash")%>',
filebrowserUploadUrl:'<%=ResolveUrl("~/ckfinder/core/connector/ASPx/connector.ASPx?command=QuickUpload&type=Files")%>',
filebrowserImageUploadUrl:'<%=ResolveUrl("~/ckfinder/core/connector/ASPx/connector.ASPx?command=QuickUpload&type=Images")%>',
filebrowserFlashUploadUrl:'<%=ResolveUrl("~/ckfinder/core/connector/ASPx/connector.ASPx?command=QuickUpload&type=Flash")%>'
3. 修改config.ascx文件中的BaseUrl = "/uploads/"(文件上傳目錄) 和CheckAuthentication()上傳身份驗證。
4. 排除示例文件夾中的fckeditor相關(guān)的文件,或者直接刪除。(引用了fckeditor相關(guān)的命名空間)
有fckeditor.ASPx popup.ASPx popups.ASPx.三個文件
之后應(yīng)該使用就基本沒問題了,但是如果項目中有幾個地方都用到了編輯器,就要每個地方都寫一段配置信息豈不是很麻煩,所以做了個簡單的控件,代碼如下:ascx文件
復(fù)制代碼 代碼如下:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="mpckeditor.ascx.cs" Inherits="mpckeditor" %>
<script language="Javascript" type="text/Javascript" src='<%=ResolveUrl("~/ckeditor/ckeditor.js")%>'></script>
<ASP:TextBox ID="mckeditor" runat="server" TextMode="MultiLine"></ASP:TextBox>
<script type="text/Javascript">
//<![CDATA[
CKEDITOR.replace( '<%=mckeditor.ClientID %>',
{
skin : 'office2003',
enterMode : Number( 2),
shiftEnterMode : Number( 1),
filebrowserBrowseUrl:'<%=ResolveUrl("~/ckfinder/ckfinder.html")%>',
filebrowserImageBrowseUrl:'<%=ResolveUrl("~/ckfinder/ckfinder.html?Type=Images")%>',
filebrowserFlashBrowseUrl:'<%=ResolveUrl("~/ckfinder/ckfinder.html?Type=Flash")%>',
filebrowserUploadUrl:'<%=ResolveUrl("~/ckfinder/core/connector/ASPx/connector.ASPx?command=QuickUpload&type=Files")%>',
filebrowserImageUploadUrl:'<%=ResolveUrl("~/ckfinder/core/connector/ASPx/connector.ASPx?command=QuickUpload&type=Images")%>',
filebrowserFlashUploadUrl:'<%=ResolveUrl("~/ckfinder/core/connector/ASPx/connector.ASPx?command=QuickUpload&type=Flash")%>'
});
//]]>
</script>
Cs文件:
復(fù)制代碼 代碼如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class mpckeditor : System.Web.UI.UserControl
{
public string value
{
set { mckeditor.Text = value; }
get { return mckeditor.Text; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
使用的地方只要把控件拖過來,后臺代碼頁很簡單Mpckeditor1.value就可以給它賦值或獲取值
復(fù)制代碼 代碼如下:
<uc1:mpckeditor id="Mpckeditor1" runat="server" value="瘋子來測試"> </uc1:mpckeditor>
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script language='Javascript'>alert('" + HttpUtility.HtmlEncode(Mpckeditor1.value) + ";')</script>");
}
Ok
AspNet技術(shù):asp.net ckeditor編輯器的使用方法,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。