百度UEditor编辑旧文章

在使用了UEditor后,有时需要编辑旧文章,查看官方文档,有输出文章内容,但没有提交方法,于是参照编辑新文章时的思路,想出了下面的方法:

一、后台定义变量

后台定义一个变量,用于表示旧文章内容:
public string words = "";

二、导入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" />

三、页面使用

<script type="text/javascript">
  var editor = new UE.ui.Editor();
  editor.render("editor");
</script>
<script type="text/plain" id="editor" name="myEditor">
  <%=words %>
</script>
<div>
        <asp:ImageButton ID="imgSubmit" runat="server" ImageUrl="~/images/submit.png" OnClick="imgSubmit_Click" />
</div>

四、后台接收

DataClassesDataContext system = new DataClassesDataContext(ConfigurationManager.ConnectionStrings["SystemConnectionString"].ConnectionString.ToString());
protected void imgSubmit_Click(object sender, ImageClickEventArgs e)
    {
        aboutus ab = system.aboutus.FirstOrDefault();
        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");
        ab.words = workContent;
        ab.updateTime = sTime;
        try
        {
            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的一个异步弹出框插件



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值