Fck编辑问题

时间:2009-12-21 16:56:51

标签: javascript jquery fckeditor

我使用FCK编辑器控件而不是textarea元素。我安装它没有问题。

但是当我想用ASP.Net 2.0的自定义验证器验证它时,我没有得到预期的结果。

这些行是我的代码:

<textarea style="width:30px;height:20px;" class="ckeditor" id="txtdescription" runat="server" name="txtdescription" cols="5" rows="10"></textarea>

<asp:CustomValidator id="descval" runat="server" ControlToValidate="txtdescription" EnableClientScript="true" Enabled="true" ValidateEmptyText="true" Display="Dynamic" ClientValidationFunction="ValidateTextDesc" Text="*" ErrorMessage="*"/> 

<asp:Button ID="buttonadd" runat="server" Text="Add text" OnClick="buttonadd_Click" />

我执行CustomValidator客户端功能的javascript代码是:

function ValidateTextDesc(source, args)
{
    var descriptiontext = document.getElementById("txtdescription");
 if ((descriptiontext.value.indexOf("<script") != -1) || (descriptiontext.value.length==0))
 {
     args.IsValid=false;
 }
 else
 {
    args.IsValid = true;
 }
 return args.IsValid;
}

我的问题是我必须单击两次提交按钮才能执行此客户端功能:

你知道为什么会出现这个问题吗? 提前致谢。 问候。 Josema。

2 个答案:

答案 0 :(得分:1)

我在黑暗中的镜头是在验证运行之前FCKeditor没有将其内容传输到textarea。

在开始验证之前,您需要调用FCKEditor的函数来手动传输内容。

它应该在FCKeditorAPI.GetInstance('FCKEditorFieldName').GetHTML()

的某个位置

答案 1 :(得分:1)

对于新版本的CKEditor(3.0.2),解决方案是使用:

CKEDITOR.instances.idoftextarea.getData();

最诚挚的问候。