在aspx文件中 使用服务器控件 表单提交会有个验证 后台直接获取CK表单提交过来的值 会报错
解决方案是 在 web.config文件中添加 <httpRuntime requestValidationMode="2.0" /> 在ASPX文件添加ValidateRequest="false"
完整代码
前台
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CKeditor.aspx.cs" Inherits="CKeditor.CKeditor" ValidateRequest="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">
<script src="ckeditor/ckeditor.js" type="text/javascript"></script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<textarea id="CK" cols="20" rows="2" runat="server"></textarea>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
<script type="text/javascript">
var ck = CKEDITOR.replace('CK');
function getdata() {
var t = ck.document.getBody().getText(); //取得纯文本
var h = ck.document.getBody().getHtml(); //取得html文本
}
</script>
后台
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CKeditor
{
public partial class CKeditor : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string a = CK.Value.ToString();
}
}
}
配置文件
<?xml version="1.0" encoding="utf-8"?>
<!--
有关如何配置 ASP.NET 应用程序的详细消息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime requestValidationMode="2.0" />
</system.web>
</configuration>