Click here to Skip to main content
12,069,450 members (69,500 online)
Click here to Skip to main content
Add your own
alternative version

Stats

146.2K views
9.4K downloads
62 bookmarked
Posted

Integrating FCKeditor in ASP.NET

, 20 Jul 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
Integrating FCKeditor in ASP.NET

Introduction

In Basic ASP.NET, FCKeditor can be easily integrated. Here is the link where I found that.

However, to integrate FCKeditor in ASP.NET MVC environment, we have to follow some tricky steps. Here I will show how to integrate using core JavaScript as well as using Jquery.

Using JavaScript

Step 1

Download the FCKeditor from here.

Step 2

Unzip the package and put in your project content directory. I like to make a directory Javascript under Content directory and put unzipped fckeditor here. I have also put fckeditorapi.js in Javascript folder. You can get more information on FCKeditor API here.

Step 3

I have added a MVC view file in Home folder and named it as Fck.aspx. To view this file, I included a method in HomeController, as follows:

/// <summary>
/// Show FCK Editor View Page
/// </summary>
public void Show()
{
    RenderView("Fck");
}  

Step 4

In Fck.aspx, include the fckeditor.js and fckeditorapi.js file:

<script type="text/javascript" src="../../Content/Javascript/fckeditor/fckeditor.js">
</script>

Include the following to replace textarea (named 'content') by FCKeditor. Here I have included InsertContent(), ShowContent() and ClearContent() methods to perform some extra actions:

<script type="text/javascript">
window.onload = function()
{
    var oFCKeditor = new FCKeditor( 'content' ) ;
    oFCKeditor.BasePath = "/Content/Javascript/fckeditor/" ;
    oFCKeditor.Height = 300;
    oFCKeditor.ReplaceTextarea() ;
}

function InsertContent()
{
    var oEditor = FCKeditorAPI.GetInstance('content') ;
    var sample = document.getElementById("sample").value;
    oEditor.InsertHtml(sample);
}

function ShowContent()
{
    var oEditor = FCKeditorAPI.GetInstance('content') ;
    alert(oEditor.GetHTML());
}

function ClearContent()
{
    var oEditor = FCKeditorAPI.GetInstance('content');
    oEditor.SetHTML("");
}
</script>

Here is the HTML content:

<div>
  <input id="sample" type="text" />
  <input id="cmdInsert" type="button" value="Insert Content" onclick="InsertContent()" />

  <input id="cmdClear" type="button" value="Clear Content" onclick="ClearContent()" />
  <br /> <br />
  <textarea id="content" cols="30" rows="10"></textarea>
  <br />
  <input id="cmdShow" type="button" value="Show Content" onclick="ShowContent()" />
</div> 

Step 5

Now build the application and run. Click the "FCK Editor" link and get the result.

Using JQuery

Step 1

Download jquery from here. I have put jquery-1.2.6.pack.js and jquery.FCKEditor.js in my "Javascript" folder.

Step 2

I have added a MVC view file in Home folder and named it as "FckJquery.aspx". To view this file, I included a method in HomeController, as follows:

/// <summary>
/// Show FCK Editor By JQuery
/// </summary>
public void View()
{
    RenderView("FckJquery");
}

Step 3

In FckJquery.aspx, include the jquery-1.2.6.pack.js, fckeditor.js and jquery.FCKEditor.js file:

<script type="text/javascript" src="../../Content/Javascript/jquery-1.2.6.pack.js">
</script>

Include the following to replace textarea (named 'content') by FCKeditor. Here I have included InsertContent(), ShowContent() and ClearContent() methods to perform some extra actions.

<script type="text/javascript">
$(document).ready(function(){
    $.fck.config = {path: '/Content/Javascript/fckeditor/', height: 300 };
    $('textarea#content').fck();
});

function InsertContent()
{
    var sample = document.getElementById("sample").value;
    $.fck.insertHtml('fck1', sample);
}

function ShowContent()
{
    alert($.fck.content('fck1', ''));
}

function ClearContent()
{
    $.fck.clearHtml('fck1');
}
</script>

Here is the HTML content:

<div>
  <input id="sample" type="text" />
  <input id="cmdInsert" type="button" value="Insert Content" onclick="InsertContent()" />

  <input id="cmdClear" type="button" value="Clear Content" onclick="ClearContent()" />
  <br /> <br />
  <textarea id="content" cols="30" rows="10"></textarea>
  <br />
  <input id="cmdShow" type="button" value="Show Content" onclick="ShowContent()" />
</div>

Step 4

In jquery.FCKEditor.js file, I have included two functions. Function insertHtml() inserts HTML content into fckeditor and clearHtml() clears the content.

// insert Html Content
insertHtml: function(i, v) {
try{
var x = FCKeditorAPI.GetInstance(i);

if(v) x.InsertHtml(v);
else return '';
}
catch(e) { return ''; };
},

// clear Html Content
clearHtml: function(i) {
try{
var x = FCKeditorAPI.GetInstance(i);

x.SetHTML('');
}
catch(e) { return ''; };
},

Step 5

Now build the application and run. Click the "FCK Editor By JQuery" link and get the result. Enjoy it!

References

Conclusion

Next I will try to give some demonstration on how to build plugins in FCKeditor. Till then, bye.

History

  • 20th July, 2008: Initial post 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jahedur Rahman Chowdhury
Software Developer (Senior)
Bangladesh Bangladesh
Software Engineer, Bangladesh.

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 3 Pin
Member 86332263-Mar-14 1:26
memberMember 86332263-Mar-14 1:26 
QuestionCKeditor Pin
Bappa Guha16-Jul-12 2:46
memberBappa Guha16-Jul-12 2:46 
QuestionExcellent! Pin
Sunasara Imdadhusen22-Sep-11 23:03
memberSunasara Imdadhusen22-Sep-11 23:03 
GeneralCould not load type 'FredCK.FCKeditorV2.FileBrowser.Config'. Pin
sajjad444415-Oct-09 5:37
membersajjad444415-Oct-09 5:37 
GeneralEntery LEVEL ??!!!!!!!!!!!! Pin
Ameen Abudbush30-Oct-08 1:46
memberAmeen Abudbush30-Oct-08 1:46 
Generalvey nice :) Pin
de1uxe6-Oct-08 10:55
memberde1uxe6-Oct-08 10:55 
GeneralRe: vey nice :) Pin
Mohammad Jahedur Rahman6-Oct-08 21:35
memberMohammad Jahedur Rahman6-Oct-08 21:35 
GeneralNice one Pin
Ashrafur Rahaman21-Jul-08 4:06
memberAshrafur Rahaman21-Jul-08 4:06 
General.NET web control Pin
Sacha Barber21-Jul-08 0:42
mvpSacha Barber21-Jul-08 0:42 
GeneralRe: .NET web control Pin
SimonRigby29-Jul-08 0:31
memberSimonRigby29-Jul-08 0:31 
GeneralRe: .NET web control Pin
Sacha Barber29-Jul-08 2:43
mvpSacha Barber29-Jul-08 2:43 
Fair enough

Sacha Barber
  • Microsoft Visual C# MVP 2008
  • Codeproject MVP 2008
Your best friend is you.
I'm my best friend too. We share the same views, and hardly ever argue

My Blog : sachabarber.net

Questionhow to apply char count? Pin
s a n t o s h21-Jul-08 0:15
members a n t o s h21-Jul-08 0:15 
AnswerRe: how to apply char count? Pin
Mohammad Jahedur Rahman21-Jul-08 0:54
memberMohammad Jahedur Rahman21-Jul-08 0:54 
GeneralRe: how to apply char count? Pin
s a n t o s h21-Jul-08 20:59
members a n t o s h21-Jul-08 20:59 
AnswerRe: how to apply char count? Pin
Mohammad Jahedur Rahman21-Jul-08 22:19
memberMohammad Jahedur Rahman21-Jul-08 22:19 
GeneralThe Editor Pin
Speednet_20-Jul-08 19:01
memberSpeednet_20-Jul-08 19:01 
GeneralRe: The Editor Pin
nsimeonov22-Jul-08 3:06
membernsimeonov22-Jul-08 3:06 
GeneralRe: The Editor Pin
Speednet_22-Jul-08 4:32
memberSpeednet_22-Jul-08 4:32 
GeneralRe: The Editor Pin
SimonRigby28-Jul-08 10:20
memberSimonRigby28-Jul-08 10:20 
GeneralRe: The Editor Pin
Speednet_28-Jul-08 19:05
memberSpeednet_28-Jul-08 19:05 
GeneralRe: The Editor Pin
SimonRigby29-Jul-08 0:20
memberSimonRigby29-Jul-08 0:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.160208.1 | Last Updated 20 Jul 2008
Article Copyright 2008 by Jahedur Rahman Chowdhury
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid