Usage of FCKEDITOR online editor in ASP. NET

Source: Internet
Author: User

You can place FCKEDITOR in any folder. By default, it is the easiest way to put FCKEDITOR in the folder. if the folder you put uses another name, modify the BasePath parameter in the configuration folder, as shown below:
OFckeditor. BasePath = "/Components/fckeditor /";

In addition, all the folders and files starting with the following line in the FCKEDITOR folder are optional and can be safely deleted from your release. They are not required when the editor is running.

How can I integrate FCKEDITOR into my page?

Currently, FCKEDITOR only provides JAVASCRIPT-based integration, so here we only show how to apply JAVASCRIPT to integrate FCKEDITOR into the site. Of course, the integration of other languages, you can refer to the example in the _ samples folder to complete
1. If the editor has been installed in the/FCKEDITOR/folder of your site. so, the first step we need to do is to add the SCRIPT tag in the header segment of the page to introduce the JAVASCRIPT integration module. for example:
<Script type = "text/javascript" src = "/fckeditor. js"> </script>

The path is changeable.

2. Now, the FCKEDITOR class can be used. There are two ways to create a FCKEDITOR editor on the page:
Method 1: inline (recommended): Insert the following code to the place where the editor needs to be inserted in the FORM tag of the page:
Script type = "text/javascript">
Var oFCKeditor = new FCKeditor ('fckeditor1 ');
OFCKeditor. Create ();
</Script>

Method 2: TEXTAREA tag replacement method (not recommended): In the ONLOAD event on the page, add the following code to replace an existing TEXTAREA tag.

<Html>
<Head>
<Script type = "text/javascript">
Window. onload = function ()
{
Var oFCKeditor = new FCKeditor ('mytextarea ');
OFCKeditor. ReplaceTextarea ();
}
</Script>
</Head>
<Body>
<Textarea id = "MyTextarea" name = "MyTextarea"> This is <B> the </B> initial value. </textarea>
</Body>
</Html>

3. Now, the editor can be used.

FCKEDITOR class reference:
The following describes the FCKEDITOR class used to create an editor on the page.

Constructor:
FCKeditor (instanceName [, width, height, toolbarSet, value])
InstanceName: Unique name of the Editor (equivalent to ID)
WIDTH: WIDTH
HEIGHT: HEIGHT
ToolbarSet: name of the toolbar set
Value: the initialization content of the editor.

Attribute:
InstanceName: Editor Instance name
Width: width. The default value is 100%.
Height: height. The default value is 200.
ToolbarSet: tool set name. For details, refer to FCKCONFIG. JS. The Default value is Default.
Value: Initialize the HTML code of the editor. The default value is null.
BasePath: The base path of the editor. The default path is/Fckeditor/folder. Be sure not to use the relative path. It is best to use the Representation Method Relative to the root path of the site and end /.
CheckBrowser: whether to check the browser compatibility before the editor is displayed. The default value is true.
DisplayErrors: Indicates whether an error is displayed. The default value is true;

Set:
Config [Key] = value;
This set is used to change the value of a configuration item, as shown in figure
OFckeditor. Config ["DefaultLanguage"] = "pt-br ";

Method:
Create ()
Create and output an editor

RepaceTextArea (TextAreaName)
Replace the text box with the editor

How to configure FCKEDITOR?
FCKEDITOR provides a set of settings for customizing its appearance, characteristics, and behavior. The main configuration file name is Fckconfig. js.
You can edit the main configuration file or define a separate configuration file. The configuration file uses the JAVASCRIPT syntax.

After modification, you can use the following syntax when creating an Editor:
Var oFCKeditor = new FCKeditor ('fckeditor1 ');
OFCKeditor. Config ['customconfigurationspath'] = '/myconfig. js ';
OFCKeditor. Create ();

Reminder: After you modify the configuration, clear the browser cache to view the effect.

Configuration Options:

AutoDetectLanguage = true/false automatic language Detection
Basehref = "" _ fcksavedurl = ": The base address of the Relative Link
ContentLangDirection = "ltr/rtl" default text direction
ContextMenu = string array, right-click the menu content
CustomConfigurationsPath = "" custom configuration file path and name
Debug = true/false whether to enable debugging. In this way, when FCKDebug. Output () is called, the content is Output in the debugging window.
DefaultLanguage = "" default language
EditorAreaCss = "" style table file in the editing area
When EnableSourceXHTML = true/false is TRUE, when the code page is switched from the visual interface to the code page, the HTML is processed as XHTML.
EnableXHTML = true/false: Can I use XHTML to replace HTML?
FillEmptyBlocks = true/false use this function to replace empty block-level elements with spaces.
FontColors = "" sets the text color list when the color picker is displayed
FontFormats = "" set the name displayed in the text format list
FontNames = "" FontNames
FontSizes = "" font size in the font size list
ForcePasteAsPlainText = true/false force paste to plain text
ForceSimpleAmpersand = true/false do not convert & symbol to XML Entity
FormatIndentator = "" specifies the characters used to indent the code in the source code format.
FormatOutput = true/false: whether to automatically format the code when output content
FormatSource = true/false whether to automatically format the code when switching to the Code view
FullPage = true/false: whether to allow editing of the entire HTML file or only the content between the bodies
GeckoUseSPAN = true/false: whether to allow the SPAN flag to replace the B, I, U flag
IeSpellDownloadUrl = "" download the spelling checker URL
ImageBrowser = true/false: whether to allow browsing of server functions
ImageBrowserURL = "" the URL that runs when browsing the server
ImageBrowserWindowHeight = "" image browser window height
Imagebrowser1_wwidth = "" image browser window width
LinkBrowser = true/false: whether to allow browsing the server when a link is inserted
LinkBrowserURL = "" browsing the server URL when inserting a link
LinkBrowserWindowHeight = "" link target browser window height
Linkbrowserdomainwwidth = "" link target browser window width
Plugins = object Registration plug-in
PluginsPath = "" plug-in folder
ShowBorders = true/false merge border
SkinPath = "" skin folder location
SmileyColumns = 12 Number of columns in the graphic operator window
SmileyImages = String Array array of image file names in the graphic character window
SmileyPath = "" folder path
SmileyWindowHeight tumbler window height
Smiley1_wwidth tumbler window width
SpellChecker = "ieSpell/Spellerpages" set the spelling checker
When StartupFocus = true/false is enabled, FOCUS to the editor.
StylesXmlPath = "" set the location of the XML file that defines the CSS style list
TabSpaces = 4 Number of space characters generated by the TAB key
ToolBarCanCollapse = true/false: whether to enable or disable the toolbar.
ToolbarSets = the TOOLBAR set can be used for objects.
ToolbarStartExpanded = true/false enable indicates whether to expand a TOOLBAR.
UseBROnCarriageReturn = true/false when you press enter, whether to generate a BR mark or a P or DIV mark

How do I customize the style list?
The FCKEDITOR style toolbar provides predefined styles defined by the XML file. The default XML style file exists in the FckStyls. xml file in the FCkEditor root folder.
The structure of the XML file is analyzed as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Styles>
<Style name = "My Image" element = "img">
<Attribute name = "style" value = "padding: 5px"/>
<Attribute name = "border" value = "2"/>
</Style>
<Style name = "Italic" element = "em"/>
<Style name = "Title" element = "span">
<Attribute name = "class" value = "Title"/>
</Style>
<Style name = "Title H3" element = "h3"/>
</Styles>

Each STYLE tag defines a STYLE. NAME is the style name displayed in the drop-down list. The ELEMENT attribute specifies the objects applicable to this STYLE, because the STYLE in FCKEDITOR is context sensitive, that is, select different objects. Only the styles defined for these objects are displayed.

Spelling check

FCKEDITOR comes with two spell checking tools, ieSpell, which is used by default. This method requires the customer to download and install the small software iespell. In addition, spellPager is also provided for spelling checks. However, since SPELLPAGER is a server-side script compiled by PHP, your WEB server must support the PHP scripting language.
For more information about how to change the spelling checker, see the configuration file.

Compression script

To improve the efficiency of Script Loading, FCKEDITOR uses the following methods to compress the script as much as possible to reduce the script size:
1. Remove the comments from the script.
2. Remove the meaningless blank in the script.
In addition, FCKEDITOR provides a tool specifically used to compress scripts so that you can reduce the file size during release,
You can copy fckeditor.packager.exe in the _packagerfolder to the fckeditor root folder to run and compress the script.

Localized FCKEDITOR
If FCKEDITOR does not provide all the languages you need (actually all of them are available), you can create a new language by yourself.
, You only need to copy the EN. JS. in addition, the Language name and the corresponding script file name must follow the RFC 3066 standard, but must be in lower case. For example, the script file name corresponding to Portuguess Language must be pt. js
If you want to target a certain country, you can add a horizontal line and a country abbreviation after the abbreviation.

During use, the system automatically detects the client language and country and uses the appropriate interface language.

After creating a new language, you must create an entry for it in "Edit/lang/fcklanguagemanager. js", as shown below:
Fck1_agemanager. AvailableLanguages =
{

En: 'English ',
Pt: 'portranges'
}

Note that the file must be saved in UTF-8 format

How can I interact with server scripts?
Please check the example to get the relevant content

In addition, use the following steps in ASP. NET:
1. Add FCKEDITOR to the toolbox
2. Drag the FCKEDITOR Control to the page
3. Specify a name for it
4. all attributes of the FCKEDITOR class can be used not only in code, but also directly as attributes of the FCKEDITOR Control. For example, to change the skin, you can specify SkinPath = "/fckeditor/editor/skins/office2003" on the UI page. NET version can be better, you can find fckeditor asp. NET 2.1 source file, then modify the control design, expose more useful properties for it, and re-compile it.
5. Use the value Attribute of the FCKEDITOR Control to obtain the POSTBACK data.
6. due to the default status, ASP. NET does not allow the submission of HTML and JAVASCRIPT content. Therefore, you must set ValidateRequest to false for pages using FCKEDITOR. (<% @ page validteRequest = "false" %>)

1. Download FckEditor 2.4, which mainly includes core files.

2. Download FckEditor 2.2. Net, including ASP. net dll files, and decompress them to any directory.

3. decompress the FckEditor 2.4 package and copy the FCKeditor folder to the root directory of the website. ASP is used here. for example, copy the test project of NET 2.0 to the root directory of test, and create a new uploads directory under the root directory to store the files uploaded by the editor.

4. Modify js configurations. open fckconfig in the FCKeditor directory. js file, set FCKConfig. change the DefaultLanguage value to zh-cn to change the interface language to simplified Chinese, and change the values of _ FileBrowserLanguage and _ QuickUploadLanguage to aspx. The optional modifications are as follows. You can modify the editor's skin and set the default value of FCKConfig. SkinPath = FCKConfig. BasePath + 'Skins/default/'to office2003 or silver. Save the changes and close the file.

5. Configure web. config.
Open the Web. Config file of the project and modify the deleettings element. The configuration is as follows:

<Deleetask>

<Add key = "FCKeditor: BasePath" value = "~ /FCKeditor/"/>

<Add key = "FCKeditor: UserFilesPath" value = "/FCKPro/Files"/>

</AppSettings>

After FCKeditor: BasePath is set, you do not need to specify the BasePath attribute every time you use the FCKeditor instance. FCKeditor: UserFilesPath is the directory where all uploaded files are located. You may ask why you want to set it to/FCKPro/Files instead ~ /Files, because FCKeditor uses this value to return the relative path of the uploaded file to the client ,~ /Files can be compiled and interpreted by ASP. NET in the service, but the static Files on the client do not understand what this is. If you use ~ /Files, the returned paths of all uploaded Files are ~ /Files, you will get the link such as this solution is to find the path. So we need to set it like the above. This is in the development phase. If the project is released after completion, remember to change/FCKPro/Files to/Files. The principle is not clear to everyone, during the development phase, VS2005 uses http: // localhost/project name/as the URL for running the project. After the project is published, a site is created on the Server. The URL is in the form of http://www.abc.com/and must be changed later. These are common errors that occur when FCKeditor2.2 + ASP. NET2.0 is used, and the cloud is unknown.

6. Reference The FredCK. FCKeditorV2.dll file in the decompressed FCKeditor. NET package in the project. The specific location is FCKeditor. Net_2.2/bin/release/FredCK. FCKeditorV2.dll.

7. register the user control. Open the default. aspx page of the test project and go

Program code
<% @ Page Language = "C #" MasterPageFile = "~ /Weblog. master "AutoEventWireup =" true "CodeFile =" article. aspx. cs "Inherits =" article "Title =" Test FckEditor "%>

Add the following code:

Program code
<% @ Register Assembly = "FredCK. FCKeditorV2" Namespace = "FredCK. FCKeditorV2" TagPrefix = "FCKeditorV2" %>

Then you can use this control on the default. aspx page:

Program code
<Fckeditorv2: fckeditorid = "FCKeditor" runat = "server" Width = "580px" EnableXHTML = "true" EnableSourceXHTML = "true" basepath = "~ /FCKeditor/"height =" 500px "> </fckeditorv2: fckeditor>

8. How to obtain the text in the editor.
This control has a property of value, which is used to obtain the text in the editor.

9. properties and events of the FCKeditor Control.
The attributes are listed as follows:

AutoDetectLanguage
BaseHref
BasePath
ContentLangDirection
CustomConfigurationsPath
Debug
DefaultLanguage
EditorAreaCSS
EnableSourceXHTML
EnableViewState
EnableXHTML
FillEmptyBlocks
FontColors
FontFormats
FontNames
FontSizes
ForcePasteAsPlainText
ForceSimpleAmpersand
FormatIndentator
FormatOutput
FormatSource
FullPage
GeckoUseSPAN
Height
ID
ImageBrowserURL
LinkBrowserURL
PluginsPath
Runat
SkinPath
StartupFocus
StylesXMLPath
TabSpaces
ToolbarCanCollapse
ToolbarSet
ToolbarStartExpanded
UseBROnCarriageReturn
Value
Visible
Width

The specific event list is as follows:

OnDataBinding
OnDisposed
OnInit
OnLoad
OnPreRender
OnUnload

10. Others

If asp. for net2.0 and theme, enable \ editor \ filemanager \ upload \ aspx \ upload. aspx and \ editor \ filemanager \ browser \ default \ connectors \ aspx \ connector. and add Theme = "" to the first line "". For example

Program code
<% @ Page language = "c #" Inherits = "FredCK. FCKeditorV2.FileBrowserConnector" AutoEventWireup = "false" Theme = "" %>

Performance

First, FCKEDITOR has excellent performance. Users can load files required by FCKEDITOR in a short time. for other online editors, this is almost difficult to solve, because too many files need to be loaded when the editor is enabled. for example, although CUTEEDITOR is more powerful than FCKEDITOR, it is also huge enough. As for FREETEXTBOX and so on, there is still a gap between its ease of use and FCKEDITOR. It can be said that, FCKEDITOR is an ingenious online editor that integrates the author's advanced object-oriented JAVASCRIPT capabilities and integrates ease of use and powerful functions.

All images, scripts, and call pages related to the editor
. Language file
. Editor skin file
. Tool-like textures, etc.

This will generate a considerable amount of traffic between the server and the client. If many files are called, even if each file is small, it will make users wait impatiently.

In version 2.0, developers can solve this problem in two ways.
That is, specify the loading sequence and script compression.

Loading Sequence
Starting from version 2.0, the editor loads resources by following these steps:
. Basic page (that is, the page where the editor is located) and JS script for loading the editor
. Used to create the editor script
The language and skin of the editor.
. Create an editor.
. Load the preset editing document content.
From now on, you can read and edit the document. However, drag-and-drop support and toolbar are unavailable.
. Load the editor engine script
. Create a toolbar and use it.
From now on, all the functions of the editor have been complete.
. Load toolbar icon

Script Compression

When any new version is packaged, the editor's JS script is preprocessed. The preprocessing steps are as follows:
. Remove all code comments
. Remove all useless white space characters.
. Merge the script into several files.

Using the above method, we can compress the script file to 50% of the original size.
After compression, the original code still exists in a folder named _ Source.

How to pack?
Then, copy it to the FCKEDITOR root folder and run it to automatically package and compress the JS script.
Note that this program is a. NET program and must be installed with. net framework.

Want to obtain support?
If you donate 15000 euros, you can get one year of free technical support (more expensive, equivalent to 0.15 million yuan, but the cost of Western Europe is quite amazing)

How to install?

1. download the latest FCKEDITOR version.
2. decompress the package to the FCKEDITOR folder in the root folder of your site (the name must be FCKEDITOR because the FCKEDITOR location has been identified in the configuration file)
3. Now, the editor can be used. To view the demo, you can access it as follows:

--------------------------------------------------------

Appendix:

I. How to set the language for uploading files

In the fckconfig. js file under the root directory of FCKeditor

Var _ FileBrowserLanguage = 'asp '; // asp | aspx | cfm | lasso | perl | php | py
Var _ QuickUploadLanguage = 'asp '; // asp | aspx | cfm | lasso | php

The two lines are changed to the editor language you need to call. If asp.net is used, it is changed to aspx;

2. Solve Chinese problems:
Add the following to web. config:
<Globalization requestEncoding = "GB2312" responseEncoding = "GB2312"/>
In this way, Chinese files can be displayed, but the URL address is also Chinese;
If the server does not parse the Chinese address properly, the image may not be browsed;
So modify: editor \ filemanager \ browser \ default \ frmresourceslist.html
In OpenFile function
Window. top. opener. SetUrl (fileUrl );
To:
Window. top. opener. SetUrl (escape (fileUrl ));

3. Set the upload directory:
1: Set in web. config:
<Deleetask>
<Add key = "FCKeditor: UserFilesPath" value = "/fck/UpLoad/"/>
</AppSettings>

2: Set in Session:
Add the following code to editor \ filemanager \ browser \ default \ connectors \ aspx \ connector. aspx:
<Script runat = "server" language = "C #">
Protected override void OnInit (EventArgs e)
{
Session ["FCKeditor: UserFilesPath"] = "/fck/UpLoad1 /";
}
</Script>

Appendix: How do I dynamically set the path of the uploaded image in asp.net?

1. Modify the value of FCKConfig. ImageBrowserURL in javascript as follows:
FCKConfig. ImageBrowserURL + = "? Path = Path of the file to be uploaded ";
For example, to upload a file to the UploadFile folder in the root directory of the site, set it:
FCKConfig. ImageBrowserURL + = "? Path =/UploadFile ";
2. Add the following program to the end of the "editor \ filemanager \ browser \ default \ connectors \ aspx \ connector. aspx" file:
<Script runat = "server" language = "C #">
Protected override void OnInit (EventArgs e)
{
If (Request. QueryString ["Path"] = null ){
Session ["FCKeditor: UserFilesPath"] = "/UpLoadFiles/"; // set the default value
} Else {
Session ["FCKeditor: UserFilesPath"] = Request. QueryString ["Path"];
}
}
</Script>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.