欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net 控件验证 FCKeditor

程序员文章站 2024-03-09 10:38:17
经过查找网上的资料,发现好像是它本身的一个问题,原文如下: with asp.net, i need to submit twice when using the requ...
经过查找网上的资料,发现好像是它本身的一个问题,原文如下:

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.


译文如下(翻译的不好,大家能看懂就好):
问:为什么在使用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",否则不起作用!

这样,再试试,ok,一次就可以直接提交了,不会出现提交两次的bug了