asp.net 控件驗證 FCKeditor
更新時間:2009年06月19日 23:32:24 作者:
FCKEditor是一個很不錯的在線編輯器,可稱得上完美,但是它有一個問題,就是在使用RequiredFieldValidator進行驗證的時候,即使內容不為空,也需要點擊兩次才能完成
經過查找網上的資料,發(fā)現好像是它本身的一個問題,原文如下:
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的文檔,發(fā)現它為客戶端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了
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的文檔,發(fā)現它為客戶端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了
相關文章
.NET?Core跨平臺資源監(jiān)控工具CZGL.SystemInfo用法
這篇文章介紹了.NET?Core跨平臺資源監(jiān)控工具CZGL.SystemInfo的用法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-02-02
Asp.net Core MVC中怎么把二級域名綁定到特定的控制器上
這篇文章主要介紹了Asp.net Core MVC中怎么把二級域名綁定到特定的控制器上,需要的朋友可以參考下2017-06-06
ASP.NET(C#) String, StringBuilder 與 StringWriter性能比較
ASP.NET(C#) String, StringBuilder 與 StringWriter性能比較...2007-08-08
.net core webapi jwt 更為清爽的認證詳解
這篇文章主要介紹了.net core webapi jwt 更為清爽的認證詳解,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-05-05
asp.net ext treepanel 動態(tài)加載XML的實現方法
當你在asp.net下面 使用Ext TreePanel直接加載服務器上XML文件會出現樹不能顯示,樹據不能正確加載的問題。2008-10-10
.NET使用CsvHelper快速讀取和寫入CSV文件的操作方法
在日常開發(fā)中使用CSV文件進行數據導入和導出、數據交換是非常常見的需求,今天我們來講講在.NET中如何使用CsvHelper這個開源庫快速實現CSV文件讀取和寫入,需要的朋友可以參考下2024-06-06

