第一步:下载百度文本编辑器: ueditor1_4_3_3-gbk-net.zip , 并把它拷贝到网站根目录下面(可以参考下里面Index.html 里面的调用案例)
第二步:在前台aspx页面加入代码:
<script type="text/javascript" charset="gbk" src="../ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="gbk" src="../ueditor/ueditor.all.min.js"> </script>
<!--建议手动加在语言,避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型,比如你在配置项目里配置的是英文,这里加载的中文,那最后就是中文-->
<script type="text/javascript" charset="gbk" src="../ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
function getContent() {
var temp = UE.getEditor('editor').getContent();
//alert(temp);
document.getElementById("<%=hd_content.ClientID %>").value = temp;
//alert(temp);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table style=" width:600px;" aligin="center" cellpadding="6" cellspacing="2" >
<tr>
<td style=" height:25px;">
内容:</td>
<td>
<div>
<script id="editor" type="text/plain" style="width: 900px; height: 500px;"></script>
<script type="text/javascript">
UE.getEditor('editor');
</script>
</div>
<asp:HiddenField ID="hd_content" runat="server" Value="" />
</td>
</tr>
<tr>
<td colspan="2" align="center" style=" height:50px;">
<asp:ImageButton ID="btnSave" runat="server" OnClientClick="return getContent();" Text="保存" ImageUrl="../Images/published_7.jpg" onclick="btnSave_Click" />
<a href="CompanyList.aspx" style="text-decoration:underline;" >返回</a>
</td>
</tr>
</table>
后台调用:采用C#编写:
public bool SaveData()
{
try
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update qb_news_content2 set ");
strSql.Append("Introduction=@Introduction");
strSql.Append(" where EnterpriseID=@EnterpriseID");
SqlParameter[] parameters = {
new SqlParameter("@Introduction", SqlDbType.NVarChar),
new SqlParameter("@EnterpriseID", SqlDbType.Int,4)};
parameters[0].Value = this.hd_content.Value.Trim();
parameters[1].Value = Request.QueryString["NewsID"];
int rows = SNS.Lib.Conn.SNSAccess.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
return false;
}
同理可得: 数据显示也用隐藏域来间接调用:this.hd_content.Value = row["content"].ToString();
怎样在前台显示数据内容呢?这个才是重点:(参考资料:http://www.cnblogs.com/ben121011/p/4541837.html)
<script type="text/javascript">
var obj = UE.getEditor('editor');
obj.ready(function () {
var temp = document.getElementById("<%=hd_content.ClientID %>").value;
alert(temp);
this.setContent(temp, true);
})
</script>
这样就OK了