今天找到了kindEditor控件很喜欢
只是自己对如何应用不很明白,尤其是使用js获得数据
后来看了很多帖子,了解到很多方法但是苦于没有完整示例所以多花很多时间,现把自己的例子放出
达到的效果:
1.点击ID="Button1" 是通过服务器端控件传输数据会刷新页面;
2.点击id="sub"按钮是通过jquery方法调用在前台获得textarea数据,其中用了2种方法:
a. var g = editor1;
alert(g.html());
community_Blog.GetMsgOfPic(g.html().toString(), msg_callBack);
b. editor1.sync();//其中editor1是我们create的kindeditror控件
var con = document.getElementById('content1').value.toString();
//var con = $('#content1').attr('value');
alert(con);
community_Blog.GetMsgOfPic(con, msg_callBack);
同时有遇到提示安全问题,我找到方法是
<pages validateRequest="false">
存在的问题:在chrome、360浏览器、以及ietester下的ie6下测试通过,但是在ietester下的ie 7 8下只有点击ID="Button1"有效果,而点击sub没效果不知为什么,如果有知道的麻烦回复一下具体的解决方法!谢谢
///aspx代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LiveMsg.aspx.cs" Inherits="Community_front_LiveMsg" %>
<!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 id="Head1" runat="server">
<meta charset="utf-8" />
<title>KindEditor ASP.NET</title>
<link rel="stylesheet" href="kindeditor/themes/default/default.css" />
<link rel="stylesheet" href="kindeditor/plugins/code/prettify.css" />
<script charset="utf-8" src="kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="kindeditor/lang/zh_CN.js"></script>
<script charset="utf-8" src="kindeditor/plugins/code/prettify.js"></script>
<script type="text/javascript" charset="utf-8" src="js/jquery-1.6.2.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
KindEditor.ready(function (K) {
var editor1 = K.create('#content1', {
cssPath: 'kindeditor/plugins/code/prettify.css',
uploadJson: 'kindeditor/asp.net/upload_json.ashx',
fileManagerJson: 'kindeditor/asp.net/file_manager_json.ashx',
allowFileManager: true,
items: [
'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
'insertunorderedlist', '|', 'emoticons', 'image', 'link'],
afterCreate: function () {
var self = this;
K.ctrl(document, 13, function () {
self.sync();
K('form[name=example]')[0].submit();
});
K.ctrl(self.edit.doc, 13, function () {
self.sync();
K('form[name=example]')[0].submit();
});
}
});
prettyPrint();
function msg_callBack(response) {
alert(response.value + 'ok');
}
//ie 7 8 下无效
$("#sub").click(function () {
//方法2
editor1.sync();
var con = document.getElementById('content1').value.toString();
//var con = $('#content1').attr('value');
alert(con);
//community_Blog.GetMsgOfPic(con, msg_callBack);
////方法1
//g = editor1;
//alert(g.html());
//community_Blog.GetMsgOfPic(g.html().toString(), msg_callBack);
})
});
});
</script>
</head>
<body>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<form id="example" runat="server">
<asp:textbox ID="title" runat="server"></asp:textbox>
<textarea id="content1" name="content1" cols="100" rows="8" style="width:700px;height:200px;visibility:hidden;"></textarea>
<br />
<asp:Button ID="Button1" runat="server" Text="发新帖" onclick="Button1_Click1" /> (提交快捷键: Ctrl + Enter)
<input type="button" id="sub" value="调用JS"/>
</form>
</body>
</html>
//////.cs代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
[AjaxPro.AjaxNamespace("community_Blog")]
public partial class Community_front_LiveMsg : System.Web.UI.Page
{
public string str;
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(Community_front_LiveMsg));
this.Label1.Text = Request.Form["content1"];
str = Request.Form["content1"];
blog newBlog = fTopic.GetFirstTopic();
if (newBlog != null)
{
this.Label1.Text = newBlog.content;
}
}
[AjaxPro.AjaxMethod]
public string GetMsgOfPic(string str)
{
try
{
string var = str;
return var;
}
catch (System.Exception ex)
{
string err = ex.Message;
return "no";
}
}
protected void AddOneTopic()
{
blog newBlog = new blog();
newBlog.title = Request.Form["title"].ToString();
newBlog.content = Request.Form["content1"].ToString();
fTopic.AddOneTopic(newBlog);
}
protected void Button1_Click1(object sender, EventArgs e)
{
AddOneTopic();
}
}