Monday, April 5, 2010

Using CompareValidator for Date entries

I've written more than a few web pages, and spent a ton of my time looking for date validation that works on both client and server side.

The solution was pretty simple really. It was already there, and I just missed it.

You can accomplish the task by using a simple ASP.NET validation CompareValidator:

Basic textbox date validation


<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Invalid Date" ControlToValidate="dtbRaw" Type="Date" Operator="DataTypeCheck" Display="Dynamic"></asp:CompareValidator>

The relevant parts:
ControlToValidate=ASP.NET Textbox control to be validated
Type=Date
Operator=DataTypeCheck

Validation that the date entry is less than the current date


<asp:CompareValidator ID="CompareValidator2" runat="server" ControlToValidate="dtbRaw"
Display="Dynamic" ErrorMessage="CompareValidator" Operator="LessThan" Type="Date"
></asp:CompareValidator>

The relevant parts:
Operator=LessThan
Type=Date
ValueToCompare=Date to use
Note: If you want to use the current date, then I recommend putting the ValueToCompare in the codebehind.

Resources:
.NET Framework Class Library

Note: I have no researched alternate date formats and/or internationalization.

3 comments:

婷妏 said...

Make yourself necessary to someone.......................................................

睿玄 said...

路過--你好嗎..很棒的BLOG.........................................

LaciRossetti199 said...

援交女豆豆出租情人視訊sogo論壇視訊辣妹桃園兼職援交辣妹視訊一對一視訊520sex日本視訊小魔女自拍av1688影音娛樂網辣手美眉甜心寶貝直播貼片免費色咪咪視訊網pc交友視訊美女ggoo免費視訊情色網咆哮小老鼠高雄援交夢中情人情趣用品sex888免費看影片波霸美女寫真sex888免費看影片視訊新竹援交留言0401成人聊天室甜心寶貝貼影片援交友留言桃園sogo 論壇080情人網視訊泳裝秀拓網交友色美眉免費看視訊免費色咪咪影片網 兼職援交聊天室ilover99a片天堂卡通aa片台灣情色網無碼avdvd色色網sexy diamond sex888入口高雄視訊辣妹自拍免費a片亞洲東洋影片hilive本土自拍天堂西門慶成人論壇 費 aaa 片試看dudu sex免費影片avdvd一夜情色妹妹免費情慾影片觀賞qq美美色網影片av免費影片日本 a 片自拍偷拍網站情色小說jp成人a 片日本avdvd女優xxx383美女寫真日本avdvd小魔女免費影城無碼avdvd無碼卡通情色情色論壇甜心寶貝貼片區Show-live視訊聊天室 情色免費A片情色偷拍免費A片一本道 a片 東京熱avdvd影片色美眉台中援交aa 片試看aaa 片試看情人輔助品成人網站做愛自拍偷拍免費試看av免費成人電影dudu sex免費 aa 片試看臺灣情色網線上免費a長片0204免費a片試看a片免費試看a片天堂台灣論壇成人a漫畫免費視訊聊天ing免費視訊美女aaa影片下載城卡通aa片免費看成人影片分享視訊聊天評比104免費成人情色文學小說