Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Validating date field
Message
From
18/07/2003 14:10:31
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00811507
Message ID:
00811586
Views:
10
Dmitry,

I find the easiest way to validate a field in ASP.NET is to use a WebControl validator. For example, if you wanted to validate the date field is formatted correctly then you would use a text control associate a control based on the following class.
protected System.Web.UI.WebControls.TextBox CompletionDate;
protected System.Web.UI.WebControls.CompareValidator CompletionDateCompareValidator;
The CompareValidator control supports the following properties:-
Type=Date
ErrorMessage=Date format is incorrect
ControlToValidate=CompletionDate
Operator=DateTypeCheck
Once you need the value as a System.DateTime type then you can convert the contents as the value should be validated correctly.
Convert.ToDateTime(CompletionDate.Text)
I am by no means an ASP.NET expert but this seems to work for my limited requirements.

Regards
Neil
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform