有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月25日 星期一
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/
來取代
http://jamesmckay.net/2008/01/missing-aspnet-tab-in-iis-on-windows-server-2003/
- Stop IIS using
iisreset /stop - Open the file
C:\WINDOWS\system32\inetsrv\MetaBase.xmlin Notepad. - Find and delete the line that says
Enable32BitAppOnWin64="TRUE" - Restart IIS using
iisreset /start - If you still don’t see your ASP.NET tab,
aspnet_regiis -ishould now work.
ASP.NET Version Switcher
來取代
2007年12月11日 星期二
使用 TableAdapter 時,如何取得 stored procedure 的 return value
Visual Studio 2005的 TableAdapter ,不會回傳 stored procedure 的 return value,解決方法之一是寫一個 partial class ,然後從 CommandCollection 的 Parameters 取得 stored procedure 的 return value ,可以參考:
http://blogs.msdn.com/smartclientdata/archive/2006/08/09/693113.aspx
namespace ICP.DAL.WebATM_DSTableAdapters{ public partial class WebATM_DSTableAdapter {
public object GetReturnValue(int commandIndex) {
return ((System.Data.SqlClient.SqlParameter)this.CommandCollection[commandIndex].Parameters[0]).Value; }
}
}
範例中的commandIndex,要從 Visual Studio 2005 產生的TableAdapter source code 中的 InitCommandCollection function 找出你要的值。
http://blogs.msdn.com/smartclientdata/archive/2006/08/09/693113.aspx
namespace ICP.DAL.WebATM_DSTableAdapters{ public partial class WebATM_DSTableAdapter {
public object GetReturnValue(int commandIndex) {
return ((System.Data.SqlClient.SqlParameter)this.CommandCollection[commandIndex].Parameters[0]).Value; }
}
}
範例中的commandIndex,要從 Visual Studio 2005 產生的TableAdapter source code 中的 InitCommandCollection function 找出你要的值。
2007年11月15日 星期四
.Net 2.0 內建的 Hex byte array converter
在 System.Runtime.Remoting.Metadata.W3cXsd2001 命名空間內 , 有.Net 2.0 內建的 Hex byte array converter:SoapHexBinary 可以作 Hex string anf byte array 之間的轉換,
http://msdn2.microsoft.com/zh-tw/library/system.runtime.remoting.metadata.w3cxsd2001.soaphexbinary_members(VS.80).aspx
http://msdn2.microsoft.com/zh-tw/library/system.runtime.remoting.metadata.w3cxsd2001.soaphexbinary_members(VS.80).aspx
2007年11月6日 星期二
讀取自然人憑證內的身分證字號後4碼
自然人憑證內的身分證字號後4碼,存放於OID=2.5.29.9 這個 extension 內,如果要用 windows 的 crypto api 讀取的話,要用到以下的 API
PCERT_EXTENSION WINAPI CertFindExtension(
__in LPCSTR pszObjId,
__in DWORD cExtensions,
__in CERT_EXTENSION rgExtensions[]
);
範例如下:
PCERT_EXTENSION pCert_extension;
PCERT_EXTENSION WINAPI CertFindExtension(
__in LPCSTR pszObjId,
__in DWORD cExtensions,
__in CERT_EXTENSION rgExtensions[]
);
範例如下:
PCERT_EXTENSION pCert_extension;
pCert_extension=CertFindExtension(szOID_SUBJECT_DIR_ATTRS,pInfo->cExtension,pInfo->rgExtension);
char szID[5];
if (pCert_extension!=NULL){
// 身分證字號後4碼在這個擴充欄位的最後面
memcpy(szID,(char *)(pCert_extension->Value.pbData)+(pCert_extension->Value.cbData-4),4);
szID[4]=0;
printf("ID:%s\n",szID);
}
2007年10月23日 星期二
C++ & UTF-8 string
自然人憑證內的中文是用UTF-8的格式儲存的,如果讀出來後直接用printf 顯示,中文會是亂碼,解決方法如下
#include <windows.h>
#include <locale.h>
char ppchDN[512]; //憑證資料
WCHAR wszUserName[1024+1]; // Unicode user name
MultiByteToWideChar( CP_UTF8, 0, ppchDN,-1, wszUserName,1024 ); //UTF-8 -> Unicode
setlocale(LC_ALL,"Chinese_Taiwan.950"); // 設定Codepage=950
wprintf(L"Issuer DN: %s\n",wszUserName); // Unicode -> 950 輸出
#include <windows.h>
#include <locale.h>
char ppchDN[512]; //憑證資料
WCHAR wszUserName[1024+1]; // Unicode user name
MultiByteToWideChar( CP_UTF8, 0, ppchDN,-1, wszUserName,1024 ); //UTF-8 -> Unicode
setlocale(LC_ALL,"Chinese_Taiwan.950"); // 設定Codepage=950
wprintf(L"Issuer DN: %s\n",wszUserName); // Unicode -> 950 輸出
2007年8月23日 星期四
如何使用 .Net 2.0 的 ConfigurationManager
你必須要先reference System.Configuration.dll,才可以用 ConfigurationManager,否則編譯時會出現
The name 'ConfigurationManager' does not exist in the current context
的錯誤。
The name 'ConfigurationManager' does not exist in the current context
的錯誤。
訂閱:
文章 (Atom)