百度ueditor编辑器在Asp.Net中使用
2013-03-12 22:06
691 查看
<%@ 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" onclick="submitData()" type="button" value="HTML控件" /></form>
<p>
</p>
<p>
</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中的
![](http://hiphotos.baidu.com/tangguoshequ/pic/item/e2a3aad9e71190ef969e5279ce1b9d16fcfa604e.jpg)
imagePath属性可以为空,更换上传文件路径需修改dialogs/image/image.html文件,如图:
![](http://hiphotos.baidu.com/tangguoshequ/pic/item/1ea74551b319ebc4e538b63f8226cffc1f17166a.jpg)
//--------------------------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;
}
}
}
}
<!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" onclick="submitData()" type="button" value="HTML控件" /></form>
<p>
</p>
<p>
</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中的
![](http://hiphotos.baidu.com/tangguoshequ/pic/item/e2a3aad9e71190ef969e5279ce1b9d16fcfa604e.jpg)
imagePath属性可以为空,更换上传文件路径需修改dialogs/image/image.html文件,如图:
![](http://hiphotos.baidu.com/tangguoshequ/pic/item/1ea74551b319ebc4e538b63f8226cffc1f17166a.jpg)
//--------------------------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;
}
}
}
}
相关文章推荐
- ASP.NET使用百度编辑器(UEditor)使用方法
- ASP.NET使用百度编辑器(UEditor)方法
- Asp.Net使用百度编辑器(ueditor)
- 百度Ueditor编辑器的使用,ASP.NET也可上传图片
- ASP.NET使用百度编辑器(UEditor)使用方法
- 封装Web Uploader 上传插件、My97DatePicker、百度 编辑器 的使用 (ASP.NET MVC)
- asp.net微信开发第十篇----使用百度编辑器编辑图文消息,上传图片、微信视频
- asp.net应用百度编辑器(UEditor)上传图片跟上次附件不成功的解决办法
- 在ASP.NET Core中使用百度在线编辑器UEditor
- 百度编辑器 ueditor1.1.8.1 For Asp.net 配置 上传功能详解
- asp.net应用百度编辑器(UEditor)上传图片和上传附件不成功的解决办法
- 在asp.net mvc中使用百度UEditor初始化内容遇到自数据库中读取的html字符串在UEditor中始终是html编码的问题
- asp.net 百度编辑器 UEditor 上传图片 图片上传配置 编辑器配置 网络连接错误,请检查配置后重试
- ASP.NET百度Ueditor编辑器实现上传图片添加水印效果
- 在ASP.NET Core中使用百度在线编辑器UEditor
- 百度UEditor1.4.3编辑器和asp.net MVC 5结合
- 百度UEditor在线编辑器上传图片提示网络连接错误,请检查配置后重试 asp.net 4.0
- 百度编辑器 ueditor1.1.8.1 For Asp.net 配置 上传功能详解
- 在ASP.NET Core中使用百度在线编辑器UEditor
- 一步步教你在Asp.net Mvc中使用UEditor编辑器