100分求修改以下HTML代码为服务器端代码,也不知道是不是叫做服务器端代码,就是想让这些代码中的FCKeditor可以正常运行就可以,不明白的可以留言给我。
下面是完整代码:Gbook.aspx
<%@ Page Language="C#"  AutoEventWireup="true" CodeBehind="Gbook.aspx.cs" Inherits="_28_1.Gbook" validateRequest="false"   %>
<%@ Register Namespace="FredCK.FCKeditorV2" Assembly="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<!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>留言本</title>
    <link href="css/css.css" rel="stylesheet" type="text/css" />
   <script type="text/javascript" src="fckeditor/fckeditor.js"></script> 
              
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
    <script src="jquery-1.6.4.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function getEditorHTMLContents(EditorName) {
           //var oEditor = FCKeditorAPI.GetInstance(EditorName);
           //alert(oEditor);
           // var oEditor = "xyzabcd"+oEditor.value.toString();
           //var editorHtml = (oEditor.GetXHTML(true));           var editor = FCKeditorAPI.GetInstance(EditorName);
           var editor2=editor.EditorDocument.body.innerText; 
                return editor2;
            }               
  </script>
</head>
<body style="background:white url(images/bg.png) repeat-x; height: 1709px;">
    <form id="form1" runat="server">
    <div class="gbook_banner">
        <img alt="" src="images/groups.png" style="width: 16px; height: 16px" />&nbsp;
        <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/login.aspx">登录</asp:LinkButton>
&nbsp;<img alt="" src="images/gift.png" style="width: 16px; height: 16px" /> 
        <asp:LinkButton ID="LinkButton2" runat="server" PostBackUrl="~/register.aspx">注册</asp:LinkButton>
&nbsp;<img alt="" src="images/list.png" style="width: 16px; height: 16px" />
        <asp:LinkButton ID="LinkButton3" runat="server" 
            PostBackUrl="~/admin/login.aspx">留言管理</asp:LinkButton>
    &nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Button 
            ID="Button4" runat="server" Height="25px" onclick="Button4_Click1" 
            Text="我的留言" Width="84px" Visible="False" />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Label ID="Label1" runat="server" Text="Label" Visible="False"></asp:Label>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="注销" 
            Visible="False" />
    &nbsp;&nbsp;&nbsp;&nbsp;
        </div>
    
    <div class="gbook_main">
       
         <div id="result">
             
  </div>
       <div style="height: 205px">
                   <script type="text/javascript">
                       var pageNo = 1; //当前页号
                       var pageItems = 3; //每页显示的行数,这个数字与da.Fill(ds,pageNo,3,"gbook");里面的3保持一致
                       var MaxPage = pageItems;                       
  
                                      function showPage(m) {
                           if (m == -1) {
                               if (pageNo < 2) {
                                   alert("已经到了首页");
                                   return;
                               };
                               MaxPage = pageItems;
                           }
                           else {
                               if (MaxPage < pageItems) {
                                   alert("已经到了末页");
                                   return;
                               };
                           }
                           pageNo += m;
                           getData();
                       }
                       $(document).ready(function () {
                           getData();
                       });
                       function getData() {
                           $.ajax({
                               type: "POST",
                               cache: false,
                               url: "WebService.asmx/Select", /* 注意后面的名字对应CS的方法名称 */
                               data: { "pageNo": (pageNo - 1) * pageItems }, /* 注意参数的格式和名称 */
                               contentType: "application/x-www-form-urlencoded",
                               dataType: "xml",
                               error: function (result) {
                                   alert(result.responseText);
                               },
                               success: function (data) {
                                   MaxPage = $(data).find('gbook').size();
                                   t = "<table border='1'>";
                                   //t = "";
                                   $(data).find('gbook').each(function (index, ele) {                                       var id = $(ele).find('id').text();
                                       var title = $(ele).find('title').text();
                                       var name = $(ele).find('name').text();
                                       var time = $(ele).find('time').text();
                                       var content = $(ele).find('content').text();
                                       var reptime = $(ele).find('reptime').text();
                                       var repcontent = $(ele).find('repcontent').text();
                                       t += "<tr>";
                                       t += "" + "ID:" + id + "<tr/>";
                                       t += "" + "标题:" + title + "<tr/>";
                                       t += "" + "留言人:" + name + "<tr/>";
                                       t += "" + "留言时间:" + time + "<tr/>";
                                       t += "" + "留言内容:" + content + "<tr/>";
                                       t += "" + "回复时间:" + reptime + "<tr/>";
                                       t += "" + "回复内容:" + repcontent + "<tr/>";
                                       t += "" + "<input type=button value='删除此留言' onclick='deleteData(" + id + ")'/><tr/>";
                                       t += "" + "<div><input type='hidden' id='FCKeditor1' name='FCKeditor1' value='' /><input type='hidden' id='FCKeditor1___Config' value='HtmlEncodeOutput=true' /><iframe id='FCKeditor1___Frame' src='fckeditor/editor/fckeditor.html?InstanceName=FCKeditor1&amp;Toolbar=Default' width='700px' height='400px' frameborder='no' scrolling='no'></iframe></div><tr/>";
                                       t += "" + "<input id=replybutton type=button value='回复此留言' onclick='replyData(" + id + ")'/><tr/>";
                                       t += "" + "<hr  color=#987cb9 size=5>" + "<tr/>";
                                       t += "</tr>";                                   })
                                   //t += "</table>";
                                   t += "<div><a href='' onclick='showPage(-1);return false;'>上一页</a> <a href='' onclick='showPage(1);return false;'>下一页</a></div>";
                                   $("#result").html(t);
                               }
                           });
                       }                                              
                       function deleteData(id) {
                           $.ajax({
                               type: "POST",
                               cache: false,
                               url: "WebService.asmx/Delete", /* 注意后面的名字对应CS的方法名称 */
                               data: { "id": id }, /* 注意参数的格式和名称 */
                               contentType: "application/x-www-form-urlencoded",
                               dataType: "xml",
                               success: function (ret) {                                   //判断 ret 删除成功再决定是否刷新getData();
                                   getData();
                               }                           });
                       }                       function replyData(id) { //回复留言函数
                          
                           var textarea1 = getEditorHTMLContents("FCKeditor1");
                          // alert(textarea1);
                           $.ajax({
                               type: "POST",
                               cache: false,
                               url: "WebService.asmx/Update", /* 注意后面的名字对应CS的方法名称 */                               data: { "id": id, "textarea1": textarea1 }, /* 注意参数的格式和名称 */
                               contentType: "application/x-www-form-urlencoded",
                               dataType: "xml",
                               success: function (ret) {
                                  // alert("2");
                                   //判断 ret 删除成功再决定是否刷新getData();
                                   getData();
                                   //alert("3");
                               }
                                                          });
                       }
                   </script>       
       </div>          
    </div>
   </form>
 </body>
</html>

解决方案 »

  1.   

    webservice.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Data;
    using System.Data.SqlClient;
    using SQLHelper;/// <summary>
    ///WebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    //若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 
    [System.Web.Script.Services.ScriptService]
    public class WebService : System.Web.Services.WebService {    public WebService () {        //如果使用设计的组件,请取消注释以下行 
            //InitializeComponent(); 
        }    [WebMethod]
        public string HelloWorld() {
            return "Hello World";
        }    [WebMethod]
        public System.Data.DataSet Select(int pageNo)
        {
            System.Data.SqlClient.SqlConnection sqlCon = new SqlConnection();
            sqlCon.ConnectionString = "server=.;uid=sa;pwd=sa;database=guestbook";
            //定义SQL语句
            string SqlStr = "select * from gbook order by id desc";
            //实例化SqlDataAdapter对象
            SqlDataAdapter da = new SqlDataAdapter(SqlStr, sqlCon);
            DataSet ds = new DataSet();
            da.Fill(ds, pageNo, 3, "gbook");
            return ds;
        }
        [WebMethod]
       public String Delete(int id)
       {
       System.Data.SqlClient.SqlConnection sqlCon = new SqlConnection();
       sqlCon.ConnectionString = "server=.;uid=sa;pwd=sa;database=guestbook";
       //定义SQL语句
       string SqlStr = "delete from gbook where id=" + id;
       //实例化SqlDataAdapter对象
       sqlCon.Open();
       SqlCommand cmd = new SqlCommand(SqlStr,sqlCon);
       int ret = cmd.ExecuteNonQuery();
       sqlCon.Close();
       if(ret > 0) return "删除成功";
       return "删除失败";
       }    //UPDATE Person SET FirstName = 'Fred' WHERE LastName = 'Wilson'     [WebMethod]
        public String Update(int id, string textarea1)
        {
            System.Data.SqlClient.SqlConnection sqlCon = new SqlConnection();
            sqlCon.ConnectionString = "server=.;uid=sa;pwd=sa;database=guestbook";
            //定义SQL语句
            //string SqlStr = "update gbook set repcontent='" + textarea1 + "' where id=" + id;
            string SqlStr = string.Format("update gbook set repcontent='{0}' where id={1}", textarea1, id);
            //实例化SqlDataAdapter对象
            sqlCon.Open();
            SqlCommand cmd = new SqlCommand(SqlStr, sqlCon);
            int ret = cmd.ExecuteNonQuery();
            sqlCon.Close();
            if (ret > 0) return "回复成功";
            return "回复失败";
        }
        
        
    }
      

  2.   

      t += "" + "<div><input type='hidden' id='FCKeditor1' name='FCKeditor1' value='' /><input type='hidden' id='FCKeditor1___Config' value='HtmlEncodeOutput=true' /><iframe id='FCKeditor1___Frame' src='fckeditor/editor/fckeditor.html?InstanceName=FCKeditor1&amp;Toolbar=Default' width='700px' height='400px' frameborder='no' scrolling='no'></iframe></div><tr/>";就是想让这句代码,可以使用:
    <FCKeditorV2:FCKeditor runat=server></FCKeditorV2:FCKeditor> 这句代替
      

  3.   

    那你直接用<FCKeditorV2:FCKeditor runat=server></FCKeditorV2:FCKeditor> 它北。为什么还搞什么DIV北。
      

  4.   

    其实,做一个东西的方法很多,
    你的这些
    t += "" + "<div><input type='hidden' id='FCKeditor1' name='FCKeditor1' value='' /><input type='hidden' id='FCKeditor1___Config' value='HtmlEncodeOutput=true' /><iframe id='FCKeditor1___Frame' src='fckeditor/editor/fckeditor.html?InstanceName=FCKeditor1&amp;Toolbar=Default' width='700px' height='400px' frameborder='no' scrolling='no'></iframe></div><tr/>";id编上序号应该就是可以使用的啊t += "" + "<div><input type='hidden' id='FCKeditor" + id + "' name='FCKeditor" + id + "' value='' /><input type='hidden' id='FCKeditor" + id + "___Config' value='HtmlEncodeOutput=true' /><iframe id='FCKeditor" + id + "___Frame' src='fckeditor/editor/fckeditor.html?InstanceName=FCKeditor" + id + "&amp;Toolbar=Default' width='700px' height='400px' frameborder='no' scrolling='no'></iframe></div><tr/>";这样的id就是唯一的了。另外,采用数据控件的方法显示数据,比较适合服务器控件的。既然采用纯html+js实现,你就没有必要使用asp:LinkButton 这些了。
      

  5.   

    谢谢,孟老这么仔细耐心的指点。这个问题解决了。
    现在程序还有一个问题,就是插入图片和表情不行,看下这里的代码有错没:  public String Update(int id, string textarea1)
        {
            System.Data.SqlClient.SqlConnection sqlCon = new SqlConnection();
            sqlCon.ConnectionString = "server=.;uid=sa;pwd=sa;database=guestbook";
            //定义SQL语句
            //string SqlStr = "update gbook set repcontent='" + textarea1 + "' where id=" + id;
            //string SqlStr = string.Format("update gbook set repcontent='{0}' where id={1}", textarea1, id);
            //实例化SqlDataAdapter对象        string SqlStr = "update gbook set repcontent=@repcontent where id=@id";
            SqlCommand cmd = new SqlCommand(SqlStr, sqlCon);
            sqlCon.Open();
            cmd.Parameters.AddWithValue("@repcontent", textarea1);
            cmd.Parameters.AddWithValue("@id", id);       
            //SqlCommand cmd = new SqlCommand(SqlStr, sqlCon);
            int ret = cmd.ExecuteNonQuery();
            sqlCon.Close();
            if (ret > 0) return "回复成功";
            return "回复失败";
        }
      

  6.   

    我是以为会不会是参数的类型有问题:public String Update(int id, string textarea1)
    这里的string textarea1 的string是不是不对,因为我数据库里用于存储回复留言内容的字段的类型是ntext
      

  7.   

    类型是ntext是正确的
    编辑器里面显示出表情了吗?图片表情跟字段类型没有关系,图片表情跟其他代码一样,就是html内容
      

  8.   

    你要坚持使用服务器控件,就采用GridView,Repeater之类的绑定数据
      

  9.   

    问题是我对jquery一窍不通啊,不然也不会费这么大劲叫你们帮我了你愿意帮我写下吗?
      

  10.   


    表情和图片都可以显示出来,并且可以读到FCK编辑器里头,就是点击 回复留言,页面无刷新了一下,就没啥了,读入的都是空值
      

  11.   

    我是想把它改为服务器端代码,这样我就懂得怎么使用FCK了,但这样修改后,代码还叫做是用Webservice+ajax实现的吗? 如果是,那就帮我改下,如果不是,那就不要改了。我这程序用webservice+ajax是前提。
      

  12.   

    FCKeditor 有现成的服务器控件。js 的那些版本的控件是给java ,php 这些用的。.net 要用js版本的得用隐藏域或者文本控件来负责保存文本,麻烦着呢。不过,无论是js版本还是服务器控件版本,用jquery获取FCKeditor的文本都是几乎一样的。