2008年2月25日 星期一

如何在 client 端 動態修改 Custom Validator 的 error message

有User的需求是希望能用alert的方式顯示出 validator 的 錯誤訊息, Validation Summary 有一個「ShowMessageBox」property 剛好可以提供這樣的功能,但是如果你的Page上有包含 Custom Validator , 而 Custom Validator的錯誤訊息會依據不同的條件顯示的話,如何在 client 動態修改 Custom Validator 的 error message呢?

重點就是要修改 Custom Validator Client script 的 sender dom 物件,說明如下:

function fn_myValidator(sender, args)
{
sender.innerHTML = "錯誤:" + new Date().toLocaleString();
sender.errormessage = "錯誤:" + new Date().toLocaleString();
args.IsValid = false;
}

ASP.net 會將 Custom Validator render 成一個 DOM object,其中的 errormessage 屬性就是validation summary control 顯示時會去讀的資料,因此只要在Custom Validator Client script改變這個值,validation summary就會Show 出新的 error message,但是如果你希望改變Custom Validator 本身顯示在 網頁上的 error message , 就需要修改 Custom Validator 的 innerHTML or innerText。

可以參考以下兩串討論

2008年2月4日 星期一

消失的IIS ASP.NET Tab(頁籤)

在Windows 2003 Server 上的 IIS ASP.NET Tab , 有時會莫名的失蹤,解決方法如下
http://jamesmckay.net/2008/01/missing-aspnet-tab-in-iis-on-windows-server-2003/
  1. Stop IIS using iisreset /stop
  2. Open the file C:\WINDOWS\system32\inetsrv\MetaBase.xml in Notepad.
  3. Find and delete the line that says Enable32BitAppOnWin64="TRUE"
  4. Restart IIS using iisreset /start
  5. If you still don’t see your ASP.NET tab, aspnet_regiis -i should now work.
另外也可以用

ASP.NET Version Switcher


來取代