百度富文本编辑器UEditor

一、配置

见: UEditor部署

二、引入js和css文件:

<script type="text/javascript" src="../../ueditor/editor_config.js"></script>
<script type="text/javascript" src="../../ueditor/editor_all.js"></script>
<link rel="Stylesheet" type="text/css" href="../../ueditor/themes/default/css/ueditor.css" />

三、使用

<div id="myEditor" class="myEditor" name="myEditor">
    </div>
    <div>
        <asp:ImageButton ID="imgSubmit" runat="server" ImageUrl="~/images/submit.png" OnClick="imgSubmit_Click" />
    </div>

 <script type="text/javascript">
                    var editor = new UE.ui.Editor();
                    editor.render("myEditor");
                    editor.ready(function(){
                        editor.setContent("课程教学空间,因你而精彩!");
                    })
    </script>

四、后台接收

protected void imgSubmit_Click(object sender, ImageClickEventArgs e)
    {
        string workContent = HttpUtility.HtmlDecode(Request.Form["myEditor"].ToString());//作业内容
        //workContent = Server.HtmlEncode(workContent);//对Html标签转码,但输出时失去了样式
        string sOrginial = "<script type=\"text/javascript\">";
        string sTo = "<script type="text/javascript">";
        workContent = workContent.Replace(sOrginial, sTo);//这两步为了原样输出js代码
        string sTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        aboutus ab = new aboutus();
        ab.words = workContent;
        ab.updateTime = sTime;
        try
        {
            system.aboutus.InsertOnSubmit(ab);
            system.SubmitChanges();
            ClientScript.RegisterStartupScript(this.GetType(), "error", "$(function(){asyncbox.alert('添加成功','提示');});window.setTimeout(function(){window.location.href='detail.aspx'},500);", true);
        }
        catch (Exception ex)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "error", "$(function(){asyncbox.alert('添加失败,请稍后重试!','提示');});window.setTimeout(function(){window.location.href='detail.aspx'},500);", true);
        }
    }

其中,asyncbox.alert是一个异步弹出框jQuery插件


你可能感兴趣的:(.net)