You are correct that the CompareValidator does not support Date + Time. You
will have to write a custom validator or consider an alternative design.
With a CustomValidator, on the server side you can use the DateTime
structure's ParseExact() method. If it throws an exception, it indicates a
bad entry.
May I suggest an alternative design? By combining both date and time into
one textbox, you are asking for the user to be very careful with formatting.
Users have to know both date and time patterns that you are expecting, plus
any separator rule. Often you assist users in entering dates with a popup
calendar. Time might have similar tools. If you allowed separate date and
time fields, you not only can add a popup calendar, but its also easier to
install client-side keystroke filtering to avoid illegal character entry.
Finally, these separate fields are easier to validate. You know that
CompareValidator can handle a date. You still would have to build a
validator for time.
My "Peter's Date Package" is a solution that includes datetextbox with popup
calendar, timeofdaytextbox, and validators for both. The two fields can
interact together. You can get and set one DateTime value and the software
interacts with both.
http://www.peterblum.com/datecontrols/home.aspx.
--- Peter Blum
www.PeterBlum.com
Email:
PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
"RSB" <rs*****@hotmail.com> wrote in message
news:O6*************@TK2MSFTNGP12.phx.gbl...
Hi Martin,
Thanks for he reply..
Now i was checking the CompareValidator and for "TYPE" property it does
not support DateTime.. it only supports Date..
Please advice.
is there any Control as such which provides me the both..
thanks
RSB
"Martin Marinov" <me********@mecrossroad.bg> wrote in message
news:ed*************@TK2MSFTNGP12.phx.gbl...
You can use CompareValidator by setting
Operator property to DataTypeCheck and Type property to DateTime, then for
the control set in the ControlToValidate the CompareValidator will get the
entered data and will try to convert it to the given type. if the data is
incorrect the CompareValidator will rise an error messsage.
When you use Operator=DataTypeCheck then the ControlToCompare is ignored
Regards
Martin
"RSB" <rs*****@hotmail.com> wrote in message
news:#H**************@TK2MSFTNGP09.phx.gbl... Hi Every one ,
IS there any Date Time Control with .Net. All i want to read is the Date
and Time in a Single Field like 12/31/2004 09:23:23AM.
if there is any then any examples for it. and if not then how to
Validate the Text field for above.
thanks
RSB