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

本文介绍如何将C#中Editor编辑的内容,包括HTML格式文本和图像,安全地上传到服务器端数据库。主要步骤包括在Editor中设计内容,通过按钮触发HTML转换,并将内容读取到服务器控件中进行存储。请注意,包含HTML标记的字符串需要特殊处理以确保安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 如何把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 οnclick="show('edit')" style="width: 80px" type="button" value="设计" /><input
                        id="Button1" οnclick="show('html')" style="width: 80px" type="button" value="HTML" />
                    <input οnclick="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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值