如何将在TinyEditor框中输入的文本保存到我的数据库中

时间:2014-04-11 19:18:35

标签: c# asp.net database tinyeditor

我是asp.net的新手。目前正在使用tinyeditor允许用户输入数据的表单上工作。我的问题是,如何在按下按钮时获取HTML编码文本并将其保存到数据库(MSSQL)?

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AboutMeEdit.aspx.cs" Inherits="InteractiveCV.AdminForms.AboutMeEdit" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
        .auto-style2 {
            height: 23px;
        }
    </style>
    <script src="../Scripts/tinyEditor/tiny.editor.packed.js"></script>
    <link href="../Styles/tinyeditor.css" rel="stylesheet" />
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <table class="auto-style1">
            <tr>
                <td class="auto-style2">Edit Your About Me in the below Text Box</td>
            </tr>
            <tr>
                <td>
        <asp:TextBox ID="tinyeditor" TextMode="MultiLine" Width="400" Height="200"  runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:RequiredFieldValidator ID="aboutmevalidate" runat="server" ControlToValidate="tinyeditor" ErrorMessage="About Me Left Empty">About Me Left Empty</asp:RequiredFieldValidator>
                </td>
            </tr>
        </table>

    </div>
    </form>
</body>
</html>

<script type="text/javascript">
    var editor = new TINY.editor.edit('editor', {
        id: 'tinyeditor',
        width: 584,
        height: 175,`enter code here`
        cssclass: 'tinyeditor',
        controlclass: 'tinyeditor-control',
        rowclass: 'tinyeditor-header',
        dividerclass: 'tinyeditor-divider',
        controls: ['bold', 'italic', 'underline', 'strikethrough', '|', 'subscript', 'superscript', '|',
            'orderedlist', 'unorderedlist', '|', 'outdent', 'indent', '|', 'leftalign',
            'centeralign', 'rightalign', 'blockjustify', '|', 'unformat', '|', 'undo',        'redo', 'n',
            'font', 'size', 'style', '|', 'image', 'hr', 'link', 'unlink', '|', 'print'],
        footer: true,
        fonts: ['Verdana', 'Arial', 'Georgia', 'Trebuchet MS'],
        xhtml: true,
        cssfile: 'custom.css',
        bodyid: 'editor',
        footerclass: 'tinyeditor-footer',
        toggle: { text: 'source', activetext: 'code', cssclass: 'toggle' },
        resize: { cssclass: 'resize' }
    });
    </script>

我有以下Codebehind:

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

namespace InteractiveCV.AdminForms
{
    public partial class AboutMeEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RIADDConnectionString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("INSERT INTO about_me (about_me) VALUES (@about_me)", conn);
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.AddWithValue("@about_me",tinyeditor.Text);
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
        }

        protected void tinyeditor_TextChanged(object sender, EventArgs e)
        {

        }
    }
}

1 个答案:

答案 0 :(得分:0)

试试TinyEditor:

<textarea  ID="tinyeditor" runat="server"></textarea >

对于您的代码,要使用tinyeditor.value()

来获取文本