Hi. If they don't want to use a regEx validator or use a calendar then there
is a very good, easy and lightweight answer to this problem. If you use C#
this solution should take only a few extra lines of code since my original
solution is targeted directly for VB features. Here we go...
This walkthrough covers my problem I had to solve directly, but you can draw
from it what you need.
1. Create a Visual Studio web/website application
2. On default.aspx, drop a wizard control.
3. In WizardStep1 drop a validationSummary, 2 textBoxes and 2
customValidator controls.
4. Set the properties of the customValidators and TextBoxes as you need.
Make sure the ControlToValidate in the customValidators point to the right
textBoxes.
5. For clarity sake, I named my customValidators DateValidator and
TimeValidator and my TextBoxes DateTextBox and TimeTextBox.
6. With step 1 showing in the designer (change wizard.ActiveStepIndex to 0),
double click the DateValidator and enter the following code in the event
handler. For the C# version, make sure you have using Microsoft.VisualBasic;
at the top of the code file and that you have added
Microsoft.VisualBasic.dll to the project references.
[C#]
if(Information.IsDate(Args.Value) == false) {
Args.IsValid = false;
}
7. Since the IsDate method is a native VB function and is contained inside a
module, all you have to do is use the IsDate method without any extra steps.
Put this code in the customValidator event:
[VB]
if(IsDate(Args.Value) = false) then
Args.IsValid = false
end if
8. In the wizard.NextButton_Click event (right click wizard control in the
designer, go to properties and click the lightening bolt button) double
click the nextButton_Click event and add this code.
]C#]
if(Page.IsValid == true) {
//Any code that you want the wizard to do when changing wizard steps if the
customValidators validate.
}
else {
e.Cancel = true;
}
[VB]
if(Page.IsValid = true) Then
'*** Whatever you want the wizard to do whenever you click next.
else
E.Cancel = true
end if
After this short bit of code (it looks like a lot, but only takes 5 minutes
to actually drop into a page) you should be able to run the page and click
the next button. Make sure you enter some valid and invalid dates and times.
This will validate/invalidate any form a date/time value can or can't take.
Trust me I pushed it to its limmits *grin*. Also make sure you put the
customValidator event handler code in both DateValidator and TimeValidator
event handlers. You can use this method of validating date/time values on a
single dateTime value as well. I just split the date and time in different
sections because it is what I had to do and it shows the availability of the
IsDate method. Have fun validating!