Summary of how to use the KindEditor editor in asp.net

Source: Internet
Author: User

It won't be used after downloading, and similar methods cannot be found on the Internet. This problem may not have been encountered. After one night of research demo and colleagues, I finally figured out how to use it. I would like to summarize it myself and hope it will help people who need it in the future. here is an example of reading and saving data from a database. For other parameters, see the official website of kindeditor.
1. First copy the following to the path to use the editor.
Copy codeThe Code is as follows: <input type = "hidden" name = "content1" id = "content1" value = '<% = databind %>'/>
<Input type = "hidden" name = "content" runat = "server" id = "content"/>
<Script type = "text/javascript" src = "KindEditor. js"> </script>
<Script type = "text/javascript">
Document. getElementById ("content "). value = document. getElementById ("content1 "). value; // this statement cannot be used directly as a server control, that is, it does not need to be used <% = this. content. clientID %>, so the data cannot be read,
Var editor = new KindEditor ("editor ");
Editor. hiddenName = "content"; // here is the name of the input hidden box with the Runat = "server" attribute
Editor. editorWidth = "100% ";
Editor. editorHeight = "280px ";
Editor. show ();
Function KindSubmit (){
Editor. data ();
}
</Script>

2. Save button
Copy codeThe Code is as follows: <asp: Button ID = "CreateAdmine" runat = "server" Height = "22" Text = "save" Width = "42" OnClientClick = "KindSubmit () "OnClick =" CreateAdmine_Click "/> // you must submit the message from the client before saving the file.

3. background reading
Aspx page:Copy codeThe Code is as follows: <input type = "hidden" name = "content" id = "content" value = '<% = EditorValue %>'/> // use the <% = variable %> to read the value of the EditorValue variable on the server side is the editor initialization content.
<Input type = "hidden" name = "contents" runat = "server" id = "contents"/>
<Script type = "text/javascript" src = "/editor/KindEditor. js"> </script>
<Script type = "text/javascript">
// Document. getElementById ("<% = this. contents. ClientID %>"). value = document. getElementById ("content"). value;
Document. getElementById ("contents"). value = document. getElementById ("content"). value;
Var editor = new KindEditor ("editor ");
Editor. hiddenName = "contents ";
Editor. skinPath = "/editor/skins/default /";
Editor. iconPath = "/editor/icons /";
Editor. imageAttachPath = "/editor/attached /";
Editor. imageUploadCgi = "/editor/upload_cgi/upload. aspx ";
Editor.css Path = "/editor/common.css ";
Editor. editorType = "simple ";
Editor. editorWidth = "500px ";
Editor. editorHeight = "300px ";
Editor. show ();
Function KindSubmit ()
{
Editor. data ();
}
</Script>

CS code:Copy codeThe Code is as follows: protected string EditorValue; // defines a variable. The client reads the value of this variable and assigns it to the editor.
Protected void Page_Load (object sender, EventArgs e)
{
If (! Page. IsPostBack)
{
BindData ();
}
}
Private void BindData ()
{
String SQL = "select Content from About where id = 1 ";
DataBase db = new DataBase ();
SqlDataReader dr = db. ReturnDataReader (SQL );
Try
{
If (dr. Read ())
{
EditorValue = dr ["Content"]. ToString (). Trim (); // assign the initial Content to it
}
}
Catch (Exception msg)
{
Response. Write (msg. Message );
}
Finally
{
Db. Close ();
}
}

4. Saved Value
Copy codeThe Code is as follows: Name = content. Value;

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.