FredCK.FCKeditorV2和vs2005中RequiredFieldValidator配合使用的问题

本文详细介绍了在使用FCKeditorV2富文本编辑器时遇到的与RequiredFieldValidator控件的兼容性问题。通过调整EnableClientScript属性及自定义验证函数,实现客户端验证,解决了需双击才触发postback的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 None.gif protected   void  Page_Load( object  sender, EventArgs e)
2 ExpandedBlockStart.gifContractedBlock.gif     dot.gif {
3InBlock.gif        this.form1.Attributes.Add  ("onsubmit""return CustomValidate()");
4ExpandedBlockEnd.gif}
FredCK.FCKeditorV2是一款相当好的开源html在线编辑器,我们在项目中用到了它,但是发现验证它是否有输入值的RequiredFieldValidator控件却每次要点击两次才能postback,比我我们原来是空的editor,打开页面之后,输入"aaaaaaaaa",点击RequiredFiledValidator,验证控件竟然认为它没有输入值。再点一下才可以完成postback,分析了一下,主要问题发生在FredCK.FCKeditorV2使用了iframe和input hidden两个控件作为客户端,这两个控件的value不能保持同步。原来以为二者根本没有添加同步功能,只是每次象动态创建的Control一样,LoadViewState加载进去的是上一次的value,然后在render方法里面在写入input hidden,但是奇怪的问题出现了,我给button加了一个客户端onclick事件,竟然发现是在验证的客户端处理中,iframe和input来个同步,郁闷。二者都不好改亚。FredCK.FCKeditorV2虽然开源,但问题又不是在这里。好不容易,终于google出来一条有建议的帖子,还是FredCK.FCKeditorV2官方的、原话这样说:

With ASP.Net, I need to submit twice when using the RequiredFieldValidator in a FCKeditor instance

FCKeditor 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.


终于明白了,呵呵,原来人家把这个没有当成bug处理。怪不得没有现成方法呢,按照他的建议,用FCKeditor JavaScript API.实现了这个功能。其实非常简单,在页面里面添加下面code
 1 None.gif
 2 None.gif     < script language = " javascript "   type = " text/javascript " >
 3 None.gif    var oEditer;
 4 None.gif    function CustomValidate()
 5 ExpandedBlockStart.gifContractedBlock.gif     dot.gif {
 6InBlock.gif        var value = oEditer.GetXHTML(true);
 7InBlock.gif        if(value=='')
 8ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 9InBlock.gif           var obj = document.getElementById('errorDiv');
10InBlock.gif           obj.innerHTML="<font color='red'>必填!</font>";
11InBlock.gif           return false;     
12ExpandedSubBlockEnd.gif        }

13InBlock.gif        return true;
14ExpandedBlockEnd.gif    }

15 None.gif    function FCKeditor_OnComplete( editorInstance )
16 ExpandedBlockStart.gifContractedBlock.gif     dot.gif {  
17InBlock.gif        oEditer = editorInstance;
18ExpandedBlockEnd.gif    }

19 None.gif     </ script >
20 None.gif
后台,

FredCK.FCKeditorV2稍稍作了改动,render事件最后一行加上writer.Write("<div id='errorDiv'></div>");
运行效果还不错。呵呵,比较简单,另外有一个比较好的工具,文本比较,经常碰到这样的情形,说两个基本没有更改的不同版本的同一页面,怎么运行效果不一样的,页面又太大。一行一行查源码,烦死人。这样近似的文件,我们可以象vss里面比较功能一样,找出两个文件不同的地方,就好说了。
工具如下: /Files/jillzhang/TextDiff.rar
另外,我参考的一些网址:
http://wiki.fckeditor.net/Troubleshooting#head-9b3ef5962fb1f578c84005f3bff3ff725d3f84c4
http://fckeditor.wikiwikiweb.de/Developer%27s_Guide/Javascript_API

转载于:https://www.cnblogs.com/jillzhang/archive/2006/09/30/518838.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值