FCKeditor 文本编辑器非空验证

来源:互联网 发布:淘宝代购直邮能作假吗 编辑:程序博客网 时间:2024/06/04 18:34

对FCKeditor进行非空验证,使用RequiredFieldValidator验证,会发现需要提交两次才能通过。如下是本人在网上查到的结果转载。

 

1、添加JS方法

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


2、添加CustomValidator验证

<asp:CustomValidator ID="CustomValidator1" runat="server" Display="Dynamic" ErrorMessage="商品介绍不能为空" ValidateEmptyText="true" ClientValidationFunction="CustomValidate" ControlToValidate="txtContent"></asp:CustomValidator>

 

ValidateEmptyText="true"   ClientValidationFunction="CustomValidate"  两个属性比较重要,如果没有设置正确,该验证视为无效。

 

 

原创粉丝点击