FCKeditor 文本編輯器非空驗證

對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"  兩個屬性比較重要,如果沒有設置正確,該驗證視爲無效。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章