如何实现富文本编辑器

时间:2013-08-27 01:26:19

标签: asp.net vb.net rich-text-editor

我想在我的项目中实现富文本编辑器,情况是当用户单击该文件时,该文件将在文本编辑器中打开。我使用vb.net和asp.net。有人有想法请帮帮我..

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

 Firstly download the ckeditor from 

https://ckeditor.com/ckeditor-4/download/

然后复制ckeditor文件夹并将其粘贴到asp.net网站中。


 Add the script <script src="ckeditor/ckeditor.js"></script> in the header 
 section '<head></head>'.

 Make sure that in <%@ %> part ValidateRequest is set false . In .NET 4 you 
 may need to do a little more. Sometimes it's necessary to also add 
 
 <httpRuntime requestValidationMode="2.0" /> 

  to web.config.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 
 ValidateRequest="false" Inherits="_Default" %>

<!DOCTYPE>

 <html xmlns="http://www.w3.org/1999/xhtml">
 <head runat="server">
 <script  type="text/javascript" src="ckeditor/ckeditor.js"></script>
 <title></title>
</head>
<body>
 <form id="form1" runat="server">
 <div>
 <asp:TextBox ID="text" runat="server" TextMode="MultiLine"></asp:TextBox>
 <script>
   CKEDITOR.replace("text"); 
 </script> 

    <asp:Button ID="Button1" runat="server" Text="save" OnClick="save"  />
     <asp:Button ID="Button2" runat="server" Text="show" OnClick="showData"  />
   
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
   
 </div>
 </form> 
</body>
</html>

In aspx.cs file.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class _Default : System.Web.UI.Page
{
   SqlConnection cn = new SqlConnection();
   protected void Page_Load(object sender, EventArgs e)
   {
      Label1.Text = "";
      cn.ConnectionString = "ConnectionString";
   }
   protected void save(object sender, EventArgs e)
   {
      cn.Open();
      SqlCommand cmd = new SqlCommand("INSERT INTO new (data) values (@data)" , cn);
      cmd.Parameters.AddWithValue("@data",text.Text);
      cmd.ExecuteNonQuery();
      text.Text = "";
      cn.Close();

    }

     protected void showData(object sender, EventArgs e)
     {
        cn.Open();
        SqlCommand cmd = new SqlCommand("SELECT data from new where id = 14", cn);
        Label1.Text = cmd.ExecuteScalar().ToString();
        cn.Close();
      }
   }
相关问题