| How to use FCKeditor in ASP.NET 2.0 |
|
FCKeditor is an open source WYSIWYG text editor that is often use with CMS applications. There are two versions of FCKeditor one is in Java and the other is for the .NET framework. In this tutorial I will show you how to use FCKeditor .Net in ASP.NET 2.0. The first thing you need to is to download the control from source forge. Make sure you download the latest one. 1. FCKEditor
After you have done all that yo can begin to use the FCKeditor control. Just place this line of code in your aspx page. <FCKeditorV2:FCKeditor ID="FCKeditor1" BasePath="/fckeditor/" runat="server" Height="400px"> </FCKeditorV2:FCKeditor> To get the value from the FCKeditor in the code behind file use FCKeditor1.Value property. Example Code: 1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test._Default" %> 2 <%@ Register assembly="FredCK.FCKeditorV2" namespace="FredCK.FCKeditorV2" tagprefix="FCKeditorV2" %> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 5 <html xmlns="http://www.w3.org/1999/xhtml" > 6 <head runat="server"> 7 <title>Untitled Page</title> 8 </head> 9 <body> 10 <form id="form1" runat="server"> 11 <div> 12 <asp:Label ID="Label1" runat="server" Text="Page Title"></asp:Label> 13 </div> 14 <br /> 15 <FCKeditorV2:FCKeditor ID="FCKeditor1" BasePath="/fckeditor/" runat="server" Height="400px"> 16 </FCKeditorV2:FCKeditor> 17 <br /> 18 <asp:Button ID="btnSave" runat="server" onclick="Button1_Click" Text="Save" 19 Width="71px" /> 20 </form> 21 </body> 22 </html>
Class File:
4 using System.Data; 5 using System.Linq; 6 using System.Web; 7 using System.Web.Security; 8 using System.Web.UI; 9 using System.Web.UI.HtmlControls; 10 using System.Web.UI.WebControls; 11 using System.Web.UI.WebControls.WebParts; 12 using System.Xml.Linq; 13 using System.Data.SqlClient; 14 using System.Data.Sql; 15 16 namespace Test 17 { 18 public partial class _Default : System.Web.UI.Page 19 { 20 protected void Page_Load(object sender, EventArgs e) 21 { 22 23 } 24 25 protected void Button1_Click(object sender, EventArgs e) 26 { 27 string connStr = "Data Source=compserver;Initial Catalog=sample;User Id=sample;Password=sample"; 28 SqlConnection conn = null; 29 30 try 31 { 32 string strInsert = "INSERT INTO Content(Page_Content) VALUES('{0}')"; 33 34 conn = new SqlConnection(connStr); 35 conn.Open(); 36 37 strInsert = string.Format(strInsert, FCKeditor1.Value); 38 39 SqlCommand cmd = new SqlCommand(strInsert, conn); 40 cmd.CommandType = CommandType.Text; 41 cmd.ExecuteNonQuery(); 42 } 43 catch (Exception ex) 44 { 45 } 46 finally 47 { 48 conn.Close(); 49 } 50 } 51 } 52 } Like this Tip? Now try to execute your code and see if it works.
Comments (12)
"
|

Thanks!