百度ueditor编辑器在Asp.Net中使用

<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" CodeBehind="ueditor_1_2.aspx.cs" Inherits="UEditor.ueditor_1_2" %>

<!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>百度ueditor编辑器在Asp.Net中使用</title>

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

    <script src="ueditor1.2.0/editor_all.js" type="text/javascript"></script>

    <link href="ueditor1.2.0/themes/default/ueditor.css" rel="stylesheet" type="text/css" />

</head>

<body>

    <form id="myForm" runat="server" method="post">

    <div>

     <!--<div id="myEditor"></div>-->

      <!--赋初值-->

    <script type="text/plain" id="myEditor">初始内容</script>

    <!--隐藏控件,由Asp.Net赋值(临时存放)-->

    <div id="HiddenDiv" runat="server" style="display:none;"></div>

    <script type="text/javascript">

             var URL = "./ueditor/";    //这里你可以配置成ueditor目录在您网站的相对路径或者绝对路径

              var editor = new baidu.editor.ui.Editor();

              

              editor.render("myEditor");

              editor.setHeight(100); //设置编辑器的高度

              //editor.setContent("为编辑器设置初值");

              editor.setContent(document.getElementById("<%=this.HiddenDiv.ClientID%>").innerHTML);//从隐藏控件中取出临时数据

    </script>

    </div>

    <asp:Button ID="Button1" runat="server" Text="服务器控件" />

    <input id="Button2" οnclick="submitData()" type="button" value="HTML控件" /></form>

    <p>

        &nbsp;</p>

    <p>

        &nbsp;</p>

</body>

</html>

<script type="text/javascript">

    function submitData() {

        if (editor.hasContents()) {  //提交条件满足时提交内容

            editor.sync();           //此处的editor是页面实例化出来的编辑器对象

            var v = editor.getContent();

            alert(v);

            document.getElementById('myForm').submit();

        }

    }

</script>

//------------------------------.cs部分--------------------------

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

namespace UEditor

{

    public partial class ueditor_1_2 : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            if (Request.Params["editorValue"] != null)

            {

                string content = Request.Params["editorValue"];//获取编辑器的内容

                this.HiddenDiv.InnerHtml = content;//保证回发不丢值

            }

            else

            {

                this.HiddenDiv.InnerHtml = "服务器端加载的初始值";

            }

        }

    }

}

//------------------------------上传图片配置-----------------------------

修改配置文件editor_config.js中的

imagePath属性可以为空,更换上传文件路径需修改dialogs/image/image.html文件,如图:


//--------------------------FilesUpload.ashx文件代码-------------------------------

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

 

namespace UEditor.Ajax

{

    /// <summary>

    /// FilesUpload 的摘要说明

    /// </summary>

    public class FilesUpload : IHttpHandler

    {

 

        public void ProcessRequest(HttpContext context)

        {

            context.Response.ContentType = "text/plain";

            ///context.Response.Write("Hello World");

            string state = "SUCCESS";

           HttpFileCollection files=context.Request.Files;

           if (files.Count > 0)

           {

               string rootPath = context.Request.MapPath("~/") + "UploadFiles/";

               string url = String.Empty;

               for (int i = 0; i < files.Count;i++ )

               {

                   try

                   {

                       files[i].SaveAs(rootPath + files[i].FileName);

                       //url = "/UploadFiles/" + files[i].FileName;

                       url = files[i].FileName;//在editor_config.js文件中配置有根目录路径

                   }

                   catch

                   {

                       state = "ERROR";

                   }

               }

               HttpContext.Current.Response.Write("{'url':'" + url + "','title':'" + context.Request.Params["pictitle"] + "','state':'" + state + "'}");

           }

        }

 

        public bool IsReusable

        {

            get

            {

                return false;

            }

        }

    }

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ueditor是由百度web前端研发部开发所见即所得的编辑器,具有轻量,可定制,注重用户体验等特点。Ueditor基于BSD开源协议,除了具有代码精简、加载迅速的轻量级特质外,还采用了分层理念,使开发者可以根据实际应用和需求自由定制。 Ueditor编辑器划分为了三层架构。其,核心层为开发者提供了诸如range、selection、domUtils类的底层API接口,间的命令插件层不仅提供了大量的基础command,还允许开发者基于核心层进行command命令的开发,而面向用户端的界面层则可以提供自由定制的用户交互界面。Ueditor开源编辑器这种拥有可配性的模式,令开发者能够根据自身需要接入任何一层进行开发。 百度编辑器 v1.4.3 更新日志: 修复hasContents接口在非ie下只有空格时判断还为真的问题 修复在粘贴word内容时,会误命cm,pt这样的文本内容变成px的问题 优化删除编辑器再创建编辑器时,编辑器的容器id发生变化的问题 修复提交jsonp请求时,callback参数的xss漏洞 新增jsp后台多种服务器配置下的路径定位 修复ZeroClipboard的flash地址参数名称错误 修复getActionUrl的bug 整理配置参数,把遗漏在代码的配置项整理到ueditor.config.js里 修复图片拉伸工具和编辑拉伸长高器的样式冲突 修复文字的unicode编码会被错误再次解析问题 添加消息提示功能,冒泡提示信息 优化上传功能提示,当后端配置项没正常加载,禁用上传功能 修复单图上传按钮和jqueryValidate不兼容的问题 简化了与jqueryValidate的结合操作,具体看_examples/jqueryValidateDemo.html 修复在删除编辑器后,再次创建时丢失原有id的问题 修复查找替换在一些块节点会导致替换错误

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值