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