ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Insert CKEditor data to database using C# and VB.Net in ASP.Net <p>Hi&nbsp;fkz2899,</p> <p>Instead of using&nbsp;txtarea use asp&nbsp;TextBox and set the&nbsp;TextMod to MultiLine.</p> <p>So that you can access the value in code behind.</p> <p>Then you can insert the value in database.</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">SQL</span></strong></p> <pre class="brush: sql">CREATE TABLE CKEditor ( Description NVARCHAR(MAX) )</pre> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;script type=&#34;text/javascript&#34; src=&#34;https://code.jquery.com/jquery-3.1.1.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://cdn.ckeditor.com/4.9.2/standard/ckeditor.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { CKEDITOR.replace(&#39;editor&#39;); }); &lt;/script&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;%--&lt;txtarea id=&#34;editor&#34; name=&#34;editor1&#34; runat=&#34;server&#34;&gt; &lt;/txtarea&gt;--%&gt; &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;editor&#34; TextMode=&#34;MultiLine&#34; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;asp:Button ID=&#34;save&#34; runat=&#34;server&#34; OnClick=&#34;save_Click&#34; Text=&#34;Save&#34; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;</pre> <p><strong><span style="text-decoration: underline;">Namespaces</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Configuration; using System.Data; using System.Data.SqlClient;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Configuration Imports System.Data Imports System.Data.SqlClient</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void save_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString)) { using (SqlCommand cmd = new SqlCommand(&#34;INSERT INTO CKEditor (Description) VALUES(@Content)&#34;)) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue(&#34;@Content&#34;, HttpUtility.HtmlEncode(editor.Text)); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub save_Click(ByVal sender As Object, ByVal e As EventArgs) Using con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString) Using cmd As SqlCommand = New SqlCommand(&#34;INSERT INTO CKEditor (Description) VALUES(@Content)&#34;) cmd.CommandType = CommandType.Text cmd.Parameters.AddWithValue(&#34;@Content&#34;, HttpUtility.HtmlEncode(editor.Text)) cmd.Connection = con con.Open() cmd.ExecuteNonQuery() con.Close() End Using End Using End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><span style="text-decoration: underline;">Form</span></p> <p><span style="text-decoration: underline;"><img src="https://i.imgur.com/i5hBajc.gif" alt="" width="399" height="352" /></span></p> <p><span style="text-decoration: underline;">Database record after inserted with&nbsp;HtmlEncode and without&nbsp;HtmlEncode</span></p> <p><span style="text-decoration: underline;"><img src="https://i.imgur.com/Hz7lzia.jpg" alt="" width="472" height="75" /></span></p> <p><strong>Note</strong>: Refer the below article to avoid the error.</p> <p><strong>A potentially dangerous Request.Form value was detected from the client&nbsp;</strong></p> <h1 class="header"><a title="ASP.Net Error: A potentially dangerous Request.Form value was detected from the client'a" href="https://www.aspsnippets.com/Articles/ASPNet-Error-A-potentially-dangerous-RequestForm-value-was-detected-from-the-client.aspx">ASP.Net Error: A potentially dangerous Request.Form value was detected from the client</a></h1>https://www.aspforums.net:443/Threads/213735/Insert-CKEditor-data-to-database-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/213735/Insert-CKEditor-data-to-database-using-C-and-VBNet-in-ASPNet/Thu, 01 Aug 2019 01:21:17 GMT