昨天经高手指点我找到了xhEditor 富文本框,感觉这个确实很不错。有些问题请假各位专家,就是fck 文本框可以直接在.cs中类似控件的方式调用。但是这个xhEditor 文本框必须通过异步的方式来提交文本框的内容吗? 我想在.CS 里面通过reques.form["txtcontents"]的方式来获得TEXTAREA 框的内容,可是为何是空的?另外,我在网上查询到说在提交的时候.NET 会提示提交内容有HTML 字符,必须通过ValidateRequest="false" 才可以。 我在.CS里面编写了一些用于过滤脏话的功能的方法,如果改成异步提交,还得需要改成javascritp 的函数来实现,想起了比较头疼。请专家,指点一下,如果在 ASP.NET 里面 使用xhEditor 吧。

解决方案 »

  1.   

    没用过,但有个处理思路你看下.
    基于javascript的HTML编辑器,都会有个公开方法,获取编辑器内容.比如[editor_实例].getContent()之类的.如果这个编辑器不是.net控件,那么你在服务器端一般是获得不了它的内容的,因为HTML编辑器多用的iframe进行文字编辑.(有些编辑器会在提交前填充编辑数据至原始textarea,则可以获取).你可以在页面的cs文件中,使用
    Page.ClientScript.RegisterOnSubmitStatement(tye,key,_getContent)
    方法注册一个客户端的提交事件:_getContent. 这个_getContent写在aspx文件中,它将在你点下提交按钮之后,页面回发至服务器之前执行.在这个_getContent方法中,获取编辑器的内容,放在你的txtcontents中,这样服务器端就可以处理了.    <script type="text/javascript">
            function _getContent() {
                var text = [这里用编辑器的方法获得内容] 
                document.getElementById('txtcontents').value = text;
            }
        </script>
      

  2.   


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Music_Default" %><!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>
        <script type="text/javascript" src="jquery/jquery-1.3.2.min.js"></script>
        <script src="xheditor.js" type="text/javascript"></script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="editor" TextMode="MultiLine" Width="600px" Height="200px" runat="server"></asp:TextBox>
        </div>
        <asp:Button ID="提交" runat="server" OnClick="Button1_Click" Text="Button" />
        </form>
    </body>
    </html>
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;public partial class Music_Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string sc = "$(pageInit);function pageInit(){ $(pageInit); function pageInit() { $('#" + this.editor.ClientID + "').xheditor(true, { tools: 'full' }); }}";
            ClientScript.RegisterStartupScript(this.GetType(), "editor", sc, true);
        }    protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Write(this.editor.Text);
        }
    }
      

  3.   

    Page.ClientScript.RegisterOnSubmitStatement(tye,key,_getContent)  tye 和key 是怎么具体写那?
      

  4.   

    type是当前页面的type,用Page.GetType()就可以了,key是一个标记,用以保证不会重复注册脚本到客户端,随便填一个字符串.
      

  5.   

    那个getContent不是说要字符串吗?怎么直接写在aspx上面?
      

  6.   

     string getContent="function getContent() {var editor = $('#txtBody').xheditor({skin:'o2007blue',upLinkUrl:'upload.aspx',upLinkExt:'zip,rar,txt',upImgUrl:'upload.aspx',upImgExt:'jpg,jpeg,gif,png',upFlashUrl:'upload.aspx',upFlashExt:'swf',upMediaUrl:'upload.aspx',upMediaExt:'avi'});var sHtml = editor.getSource();document.getElementById('txtBody').value = sHtml;}";
            Page.ClientScript.RegisterOnSubmitStatement(this.GetType(),"yff",getContent); string a = txtBody.Value;为什么这样子获取不到值啊