FCKEditor使用非空验证时必须点击两次的解决办法

FCKEditor是一个很不错的在线编辑器,可称得上完美,但是它有一个问题,就是在使用RequiredFieldValidator进行验证的时候,即使内容不为空,也需要点击两次才能完成,经过查找网上的资料,发现好像是它本身的一个问题,原文如下:
With ASP.Net, I need to submit twice when using the RequiredFieldValidator in a FCKeditor instanceFCKeditor will not work properly with the Required Field Validator when the "EnableClientScript" property of the validator is set to "true" (default). Due to a limitation in the default validation system, you must set it to "false". 
If you want to do client side validation, you must use a Custom Validator instead and provide the appropriate validation function, using the FCKeditor JavaScript API.

译文如下(翻译的不好,大家能看懂就好):
问:为什么在使用ASP.NET的RequiredFieldValidator时,我需要提交两次
答:当RequiredFieldValidator的EnableClientScript属性被设置成true时,FCKEditor不能很好的支持RequiredFieldValidator,为了解除这个限制,你必须把这个属性设置成为false
如果你希望使用客户端验证,你必须使用Custom Validator制作一个非空验证来替换RequiredFieldValidator,在其中使用FCKeditor JavaScript API即可。

看了这篇文章,我就去找FCKeditor JavaScript API的文档,发现它为客户端JavaScript的调用提供了一些属性和方法,于是乎,就按上述的回答写了一段JavaScript脚本来完成了验证。

详细解决方法:首先添加Javascript脚本:
<script language="javascript"  type="text/javascript">
var oEditer;
function CustomValidate(source, arguments)
{
    var value = oEditer.GetXHTML(true);
    if(value=="")
    {
       arguments.IsValid = false;    
    }
    else
    {
        arguments.IsValid = true;
    }
}
function FCKeditor_OnComplete( editorInstance )

    oEditer = editorInstance;
}
</script>
然后添加CustomValidator,设置ClientValidationFunction="CustomValidate",注意千万别忘了ValidateEmptyText="True",否则不起作用!
这样,再试试,哈哈,一次就可以直接提交了,不会出现提交两次的bug了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值