Steven Evers
Steven Evers

Reputation: 17196

OnValidating Event in a custom control

When does the OnValidate event fire in the life-cycle of a control?

I'm creating a DateBox that will allow the user to enter a date in MM/DD/YYYY format (text) and need to verify that the date is in that format. It'll never be converted to a date (stored as string) but I would like to know the best time to validate that data (and provide feedback).

Note: It may seem a bit like re-inventing the wheel, but the app that I'm writing gets deployed to a tablet-pc and the winforms DateTimePicker is hell to edit with a stylus and my users just want to be able to write in the date.

Upvotes: 0

Views: 661

Answers (2)

mbillard
mbillard

Reputation: 38842

OnValidate happens after the Loading events (source)

You should validate on the client-side (javascript) AND server side either using the OnValidate or when handling the submission of the form (or both).

Upvotes: 1

Canavar
Canavar

Reputation: 48088

MaskedTextBox Control might help you.

Upvotes: 1

Related Questions