Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Validating date field
Message
De
18/07/2003 14:10:31
 
 
À
18/07/2003 11:14:41
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00811507
Message ID:
00811586
Vues:
11
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform