Save (Insert) and Retrieve (Display) TinyMCE contents to database in ASP.Net

nedash
 
on Apr 09, 2014 09:59 AM
8915 Views

Hi

I used tinyMCE in my edit.aspx page that bind it from database

 

 TextBox1.Text = _dr["description"].ToString();

and users can change this editor text and click on button and update information

below is code

 

 

 

 

 protected void ImageButton2_Click1(object sender, ImageClickEventArgs e)
    {
    
             string data = Session["behcode"].ToString();
             SqlCommand _cmd = new SqlCommand("insertstate", _cn);
            _cmd.CommandType = CommandType.StoredProcedure;
            _cn.Open();
            _cmd.Parameters.AddWithValue("@Name", txtstore.Text);
            _cmd.Parameters.AddWithValue("@Ownername", txtowner.Text);
            _cmd.Parameters.AddWithValue("@Description", TextBox1.Text);
  _cmd.ExecuteNonQuery();
 Session["Message"] = true;

            _cn.Close();


    }



 

in database I have House_info table that has description column and if I enter text in textbox1 it update description column

now problem is when I enter text in textbox1 it didn't change text and didn't update data in database...

I put breakpoint in imagebutton2_click event and see in this code

 

 _cmd.Parameters.AddWithValue("@Description", TextBox1.Text);

it didn't send any text from textbox1 and show text that bind from database and didn't change it...

so what should I do?

Best Regards

Neda

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
Mudassar
 
on Apr 11, 2014 09:13 AM
on Sep 25, 2014 02:38 AM

This way

HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>TinyMCE ASP.Net Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>
            <script type="text/javascript" src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>
            <script type="text/javascript">
                tinymce.init({ selector: 'textarea' });
          
            </script>
            <asp:TextBox ID="txtTinyMCE" TextMode="MultiLine" runat="server" />
        </div>
        <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="SaveToDatabase" />
    </div>
    </form>
</body>
</html>

Namespaces

using System.Data;
using System.Configuration;
using System.Data.SqlClient;

Code

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        string constring = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        using (SqlConnection con = new SqlConnection(constring))
        {
            using (SqlCommand cmd = new SqlCommand("SELECT tinymce_data FROM tblTinyMCE", con))
            {
                cmd.CommandType = CommandType.Text;
                con.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    this.txtTinyMCE.Text = dr["tinymce_data"].ToString();

                }
                con.Close();
            }
        }

    }
}
protected void SaveToDatabase(object sender, EventArgs e) { string constring = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; using (SqlConnection con = new SqlConnection(constring)) { using (SqlCommand cmd = new SqlCommand("UPDATE tblTinyMCE Set tinymce_data = @TinyMCEData", con)) { con.Open(); cmd.Parameters.AddWithValue("@TinyMCEData", this.txtTinyMCE.Text.Trim()); cmd.ExecuteNonQuery(); con.Close(); } } Response.Redirect(Request.Url.AbsoluteUri); }