C#如何把Editor设计的内容上传到服务器端

来源:互联网 发布:如何破解网络尖兵 编辑:程序博客网 时间:2024/05/30 22:59

 如何把Editor设计的内容上传到服务器端
      实现这样的功能就可以把设计的HTML格式的(含标记)的文本保存到服务器端数据库中二进制字段中,实现内容的动态保存和加载。
      设计步骤:
      1.添加内容到Editor(包括:字体、图片 等.......)
      2.按【HTML】按钮
      3.按【读取】按钮,把Editor设计的标记字符串填入服务器控件Text
注意:包含HTML标记的字符串被认定为不安全的。

      4.若要直接读取请在【读取】Button2按钮,中属性OnClientClick="show('html') 执行与按钮【HTML】相同的js函数

(由于博客图片审核功能尚未完成,普通用户暂时关闭引用站外图片功能,请您谅解)

图片请到这里查看:http://user.qzone.qq.com/14035344/blog/1310785498

code:

using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {    }    protected void Button2_Click(object sender, EventArgs e)    {        Label1.Text = content.InnerText .ToString ();        TextBox1.Text = content.InnerText.ToString();    }}


 

 

html:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register Src="UserControl/HtmlEdit.ascx" TagName="HtmlEdit" TagPrefix="uc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server">    <title>无标题页</title></head><body>    <form id="form1" runat="server">    <div>        <table border="1" cellpadding="0" cellspacing="0" style="width: 500px">            <tr>                <td>                    <div id="html" style="display: none">                        <textarea id="content" runat="server" name="content" rows="10" style="width: 500px;                            height: 280px"></textarea></div>                    <div id="edit">                        <uc1:HtmlEdit ID="HtmlEdit1" runat="server" />                    </div>                </td>            </tr>            <tr>                <td>                    <input onclick="show('edit')" style="width: 80px" type="button" value="设计" /><input                        id="Button1" onclick="show('html')" style="width: 80px" type="button" value="HTML" />                    <input onclick="alert(oEditor.document.body.innerHTML);" type="button" value="getContent" /></td>            </tr>        </table>          <table style="width: 510px">            <tr>                <td style="height: 44px">                    如何把Editor设计的内容上传到服务器端<br />                          实现这样的功能就可以把设计的HTML格式的(含标记)的文本保存到服务器端数据库中二进制字段中,实现内容的动态保存和加载。<br />                          设计步骤:<br />                          1.添加内容到Editor(包括:字体、图片 等.......)<br />                          2.按【HTML】按钮<br />                          3.按【读取】按钮,把Editor设计的标记字符串填入服务器控件Text<br />                    注意:包含HTML标记的字符串被认定为不安全的。<br />                    <br />                          4.若要直接读取请在【读取】Button2按钮,中属性OnClientClick="show('html') 执行与按钮【HTML】相同的js函数                </td>                <td style="height: 44px; width: 3px;">                </td>                <td style="height: 44px; width: 2px;">                </td>            </tr>            <tr>                <td>                    <asp:Button ID="Button2" runat="server" Text="读取" OnClick="Button2_Click" OnClientClick="show('html')" /></td>                <td style="width: 3px">                </td>                <td style="width: 2px">                </td>            </tr>            <tr>                <td style="height: 60px">                    <asp:TextBox ID="TextBox1" runat="server" Height="49px" TextMode="MultiLine" Width="482px"></asp:TextBox></td>                <td style="height: 60px; width: 3px;">                </td>                <td style="height: 60px; width: 2px;">                </td>            </tr>            <tr>                <td style="height: 32px">                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></td>                <td style="width: 3px; height: 32px">                </td>                <td style="width: 2px; height: 32px">                </td>            </tr>        </table>    </div>    </form></body></html>


                      作者:段利庆   QQ;14035344