Insert CKEditor data to database using C# and VB.Net in ASP.Net

Last Reply one month ago By dharmendr

Posted one month ago

 I have used ckeditor this way...please check .cs code

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" EnableEventValidation="false" AutoEventWireup="true" CodeBehind="WebForm7.aspx.cs" Inherits="Green_Garden.WebForm7" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="https://cdn.ckeditor.com/4.9.2/standard/ckeditor.js">
   </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <form id="f1">
        <table>
            <tr>
                <td><txtarea id="editor" class="editor1" name="editor1" rows="10" cols="80"></txtarea></td>
            </tr>
            <tr>
                <td><asp:Button ID="save" runat="server" OnClick="save_Click" Text="Save" /></td>
            </tr>
        </table>
    </form>
   <script>
       var editor = CKEDITOR.replace('editor');
   </script>
</asp:Content>

 

namespace Green_Garden
{
    public partial class WebForm7 : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["fkzala"].ToString());

        protected void save_Click(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand("insert description(text) values(@txt)");
            con.Open();
            cmd.Connection = con;
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.AddWithValue("@txt", WebUtility.HtmlEncode(Request.Form["editor"]).ToString());
            int row;
            try
            {
                row = cmd.ExecuteNonQuery();
                if (row > 0)
                {
                    Session["category"] =  Request.Form["editor"].ToString();
                    ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('Added Successfully! ');", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('Please Add again ! ');", true);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                    con.Close();
            }
        }
    }
}

 

This question does not have replies that have been liked.