私は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>
私は次のコードビハインドを持っています:
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)
{
}
}
}