程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 百度UEditor編輯舊文章

百度UEditor編輯舊文章

編輯:C#入門知識

在使用了UEditor後,有時需要編輯舊文章,查看官方文檔,有輸出文章內容,但沒有提交方法,於是參照編輯新文章時的思路,想出了下面的方法:

一、後台定義變量
後台定義一個變量,用於表示舊文章內容:
[csharp]
public string words = ""; 

public string words = "";

二、導入js和css文件
[javascript]
<script type="text/javascript" src="../../ueditor/editor_config.js"></script> 
 
<script type="text/javascript" src="../../ueditor/editor_all.js"></script> 

<script type="text/javascript" src="../../ueditor/editor_config.js"></script>

<script type="text/javascript" src="../../ueditor/editor_all.js"></script>[css] view plaincopyprint?<link rel="Stylesheet" type="text/css" href="../../ueditor/themes/default/css/ueditor.css" /> 

<link rel="Stylesheet" type="text/css" href="../../ueditor/themes/default/css/ueditor.css" />三、頁面使用
[javascript]
<script type="text/javascript"> 
  var editor = new UE.ui.Editor(); 
  editor.render("editor"); 
</script> 
<script type="text/plain" id="editor" name="myEditor"> 
  <%=words %> 
</script> 

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

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

四、後台接收
[csharp]
DataClassesDataContext system = new DataClassesDataContext(ConfigurationManager.ConnectionStrings["SystemConnectionString"].ConnectionString.ToString()); 

DataClassesDataContext system = new DataClassesDataContext(ConfigurationManager.ConnectionStrings["SystemConnectionString"].ConnectionString.ToString());[csharp]
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); 
        } 

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的一個異步彈出框插件

 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved