我今天学习了下用FCKeditor,但是想把其中的内容保存到数据库中就是保存不进去,而其他字段的数据则能保存进去。大家帮忙看看是不是我的代码什么地方有问题?
MyFck.aspx<%@ Register TagPrefix="fckeditorv2" Namespace="FredCK.FCKeditorV2" Assembly="FredCK.FCKeditorV2" %>
<%@ Page language="c#" Codebehind="MyFck.aspx.cs" AutoEventWireup="false"  validateRequest=false Inherits="MyMenu.MyFck" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>AdminFileAdd</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="admin.css" type="text/css" rel="stylesheet">
</HEAD>
<body class="right">
<form id="Form1" method="post" runat="server">
<div>添加文章</div>
<div class="main">
<ul>
<li>
标题:<asp:textbox id="title" runat="server" Width="250px" MaxLength="50"></asp:textbox>
<li>
<FCKEDITORV2:FCKEDITOR id="content" runat="server" Width="90%" BasePath="FCKeditor/" Height="350px"></FCKEDITORV2:FCKEDITOR>
<li>
<asp:button id="add" runat="server" Text="提 交"></asp:button><asp:label id="lblErrorShow" runat="server" ForeColor="Red"></asp:label></li></ul>
</div>
</form>
</body>
</HTML>MyFck.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Common;namespace MyMenu
{
/// <summary>
/// MyFck 的摘要说明。
/// </summary>
public class MyFck : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox title;
protected FredCK.FCKeditorV2.FCKeditor content;
protected System.Web.UI.WebControls.Label lblErrorShow;
protected System.Web.UI.WebControls.Button add;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.add.Click += new System.EventHandler(this.add_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void add_Click(object sender, System.EventArgs e)
{
string sSql;
if(title.Text=="")
{
lblErrorShow.Text = "标题不能为空!";
return;
} if(content.Value=="")
{
lblErrorShow.Text = "内容不能为空!";
return;
}
sSql = "Insert into news(newstitle,newscontent) Values('"
+title.Text.Trim().ToString()+"','"+content.Value.Trim()+"')";
AppGlobal.AppDataAccess.ExeSQL(sSql);
}
}
}

解决方案 »

  1.   

    当FCKeditor中输入数据,怎么还是执行这句??怎么content.Value一直会为空呢?
    是不是什么地方设置没对??
    if(content.Value=="")
    {
    lblErrorShow.Text = "内容不能为空!";
    return;
    }
      

  2.   

    程序出错了吗?sSql = "Insert into news(newstitle,newscontent) Values('"
    +title.Text.Trim().ToString()+"','"+content.Value.Trim()+"')";
    如果title.Text、content.Value里面含有单引号的话,sql是不能执行的,
    当然也就不能入库!
      

  3.   

    没有单引号,title.Text就入库了,content.Value中无论输入什么数据就是保存不进数据库
      

  4.   

    明明有输入数据,怎么在点击了按钮后title.Text就为空了呢?而且FCKeditor中刚刚输入的数据也因为自动刷新而为空了?请问到底是怎么回事呢?是不是什么地方设置不对啊?
      

  5.   

    明明有输入数据,怎么在点击了按钮后content.Value就为空了呢?而且FCKeditor中刚刚输入的数据也因为自动刷新而为空了?请问到底是怎么回事呢?是不是什么地方设置不对啊?
      

  6.   


    试试这个:
    string ss=Request.Params["content"].ToString();
    Response.Write(ss);
    Response.End();
    测试是否有获取数据
      

  7.   

    content.Value应该改为Request["content"],因为FCK是在客户端改变的,所以直接content.Value根本取不到值.
      

  8.   

    还是取不到content里面的值,我直接给content.Value付值可以保存。但是当我在FCKeditor中输入值的时候,就是取不到我输入的数据啊。点击保存按钮后总是为空,到底杂个回事呢?
      

  9.   

    有没有人用过FCKeditor的啊?帮忙看看是什么问题
      

  10.   

    这样子当然不能正常写入啦
    sql语句中含有引号,来源于content ,要调用sever.Encode方法,将其编码才能写入
    读出的时候再调用server.Decode()方法显示出来
    写入前
    content=server.Encode(content);
    读出后显示之前
    content=server.Decode(content);大小写可能有问题,自己写一下吧
      

  11.   

    谁那有fckeditor2.3.2的版本啊,包括ZIP文件和DLL文件,外国的网站现在还是访问不了,可能是海底电缆还是没修好.访问sourceforg网站总是打不开网页,我也要用,可是怎么也下载不下来,那个兄弟帮帮忙啊