如何将在TinyEditor框中输入的文本保存到数据库中 [英] How do I save text entered in a TinyEditor box to my database
本文介绍了如何将在TinyEditor框中输入的文本保存到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是asp.net的新手。当前正在处理使用tinyeditor允许用户输入数据的表单。我的问题是,如何在按下按钮后获取HTML编码的文本并将其保存到数据库(MSSQL)?
I am new to asp.net. Currently working on a form that uses tinyeditor to allow a user to input data. My question is, how can I get that HTML encoded text and save it to the database (Its MSSQL) upon pressing a button?
<%@ 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>
我后面有以下代码:
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)
{
}
}
}
推荐答案
尝试使用TinyEditor:
Try this for TinyEditor:
<textarea ID="tinyeditor" runat="server"></textarea >
对于后面的代码,使用 tinyeditor.value( )
And for your code behind, to get the text use tinyeditor.value()
这篇关于如何将在TinyEditor框中输入的文本保存到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文