Click here to Skip to main content
6,295,667 members and growing! (15,323 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General License: The Code Project Open License (CPOL)

Integrating FCKeditor in ASP.NET

By Mohammad Jahedur Rahman

Integrating FCKeditor in ASP.NET
Javascript, CSS, HTML, XHTML, ASP, ASP.NET, Ajax
Version:2 (See All)
Posted:20 Jul 2008
Views:23,546
Bookmarked:29 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
8 votes for this article.
Popularity: 3.31 Rating: 3.67 out of 5
2 votes, 25.0%
1

2

3
2 votes, 25.0%
4
4 votes, 50.0%
5

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>
<script type="text/javascript" src="../../Content/Javascript/fckeditorapi.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>
<script type="text/javascript" src="../../Content/Javascript/fckeditor/fckeditor.js">
</script>
<script type="text/javascript" src="../../Content/Javascript/jquery.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">
$(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)

About the Author

Mohammad Jahedur Rahman


Member
Senior Software Engineer in Brain Station-23, Bangladesh.
Occupation: Software Developer (Senior)
Company: Brain Station-23
Location: Bangladesh Bangladesh

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 17 of 17 (Total in Forum: 17) (Refresh)FirstPrevNext
GeneralEntery LEVEL ??!!!!!!!!!!!! PinmemberAmeen Abudbush1:46 30 Oct '08  
Generalvey nice :) Pinmemberde1uxe10:55 6 Oct '08  
GeneralRe: vey nice :) PinmemberMohammad Jahedur Rahman21:35 6 Oct '08  
GeneralNice one PinmemberAshrafur Rahaman4:06 21 Jul '08  
General.NET web control PinmvpSacha Barber0:42 21 Jul '08  
GeneralRe: .NET web control PinmemberSimonRigby0:31 29 Jul '08  
GeneralRe: .NET web control PinmvpSacha Barber2:43 29 Jul '08  
Generalhow to apply char count? Pinmembers a n t o s h0:15 21 Jul '08  
AnswerRe: how to apply char count? PinmemberMohammad Jahedur Rahman0:54 21 Jul '08  
GeneralRe: how to apply char count? Pinmembers a n t o s h20:59 21 Jul '08  
AnswerRe: how to apply char count? PinmemberMohammad Jahedur Rahman22:19 21 Jul '08  
GeneralThe Editor PinmemberSpeednet_19:01 20 Jul '08  
GeneralRe: The Editor Pinmembernsimeonov3:06 22 Jul '08  
GeneralRe: The Editor PinmemberSpeednet_4:32 22 Jul '08  
GeneralRe: The Editor PinmemberSimonRigby10:20 28 Jul '08  
GeneralRe: The Editor PinmemberSpeednet_19:05 28 Jul '08  
GeneralRe: The Editor PinmemberSimonRigby0:20 29 Jul '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 20 Jul 2008
Editor: Deeksha Shenoy
Copyright 2008 by Mohammad Jahedur Rahman
Everything else Copyright © CodeProject, 1999-2009
Web11 | Advertise on the Code Project