asp.net 控件驗(yàn)證 FCKeditor
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時(shí),我需要提交兩次
答:當(dāng)RequiredFieldValidator的EnableClientScript屬性被設(shè)置成true時(shí),F(xiàn)CKEditor不能很好的支持RequiredFieldValidator,為了解除這個(gè)限制,你必須把這個(gè)屬性設(shè)置成為false 如果你希望使用客戶端驗(yàn)證,你必須使用Custom Validator制作一個(gè)非空驗(yàn)證來替換RequiredFieldValidator,在其中使用FCKeditor JavaScript API即可。
看了這篇文章,我就去找FCKeditor JavaScript API的文檔,發(fā)現(xiàn)它為客戶端JavaScript的調(diào)用提供了一些屬性和方法,于是乎,就按上述的回答寫了一段JavaScript腳本來完成了驗(yàn)證。
詳細(xì)解決方法:首先添加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,設(shè)置ClientValidationFunction="CustomValidate",注意千萬別忘了ValidateEmptyText="True",否則不起作用!
這樣,再試試,OK,一次就可以直接提交了,不會(huì)出現(xiàn)提交兩次的bug了
相關(guān)文章
C#讀取中文字符及清空緩沖區(qū)的實(shí)現(xiàn)代碼
有一個(gè)txt的中英文語料庫文件,內(nèi)容是英文一句中文一句相間的,共3000行,需要把英文句和中文句分開,放在單獨(dú)的txt文件中。2010-12-12
.NET?Core跨平臺(tái)資源監(jiān)控工具CZGL.SystemInfo用法
這篇文章介紹了.NET?Core跨平臺(tái)資源監(jiān)控工具CZGL.SystemInfo的用法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-02-02
Asp.net Core MVC中怎么把二級(jí)域名綁定到特定的控制器上
這篇文章主要介紹了Asp.net Core MVC中怎么把二級(jí)域名綁定到特定的控制器上,需要的朋友可以參考下2017-06-06
記一次EFCore類型轉(zhuǎn)換錯(cuò)誤及解決方案
這篇文章主要介紹了記一次EFCore類型轉(zhuǎn)換錯(cuò)誤及解決方案,幫助大家更好的理解和學(xué)習(xí)使用asp.net core,感興趣的朋友可以了解下2021-03-03
ASP.NET(C#) String, StringBuilder 與 StringWriter性能比較
ASP.NET(C#) String, StringBuilder 與 StringWriter性能比較...2007-08-08
MVC使用T4模板生成其他類的具體實(shí)現(xiàn)學(xué)習(xí)筆記2
這篇文章主要為大家詳細(xì)介紹了MVC使用T4模板生成其他類的具體實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09
.net core webapi jwt 更為清爽的認(rèn)證詳解
這篇文章主要介紹了.net core webapi jwt 更為清爽的認(rèn)證詳解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-05-05
asp.net ext treepanel 動(dòng)態(tài)加載XML的實(shí)現(xiàn)方法
當(dāng)你在asp.net下面 使用Ext TreePanel直接加載服務(wù)器上XML文件會(huì)出現(xiàn)樹不能顯示,樹據(jù)不能正確加載的問題。2008-10-10
.NET使用CsvHelper快速讀取和寫入CSV文件的操作方法
在日常開發(fā)中使用CSV文件進(jìn)行數(shù)據(jù)導(dǎo)入和導(dǎo)出、數(shù)據(jù)交換是非常常見的需求,今天我們來講講在.NET中如何使用CsvHelper這個(gè)開源庫快速實(shí)現(xiàn)CSV文件讀取和寫入,需要的朋友可以參考下2024-06-06

