gilkesy
asked on
Custom validation of date when DropDown Lists are used
I have a form where a client can enter a date using 3 DropDown lists (Day, Month, Year)
I need to create a custome validation to check whether the date is valid. I'm not sure how to do this because custom validation seems to only apply to a single control and not 3 controls as is the case here.
How should I tackle this?
I need to create a custome validation to check whether the date is valid. I'm not sure how to do this because custom validation seems to only apply to a single control and not 3 controls as is the case here.
How should I tackle this?
ASKER
Well I was thinking something along the lines of this:
If IsDate(dropDOBDD.SelectedV alue & "/" & dropDOBMM.SelectedValue & "/" & dropDOBYY.SelectedValue) = False Then
DOBValidator.Text = "Invalid Date"
e.IsValid = False
Else
e.IsValid = True
Session("DOB") = CDate(dropDOBDD1.SelectedV alue & "/" & dropDOBMM1.SelectedValue & "/" & dropDOBYY1.SelectedValue)
End If
If IsDate(dropDOBDD.SelectedV
DOBValidator.Text = "Invalid Date"
e.IsValid = False
Else
e.IsValid = True
Session("DOB") = CDate(dropDOBDD1.SelectedV
End If
Right... That looks like option 1 (server-side). The drawback to server-side validation is that it requires a postback. If you write roughly equivalent code in java, then it runs on the client, and the user can't postback invalid data -- plus, they don't have to wait for the error message.
ASKER
I'm going to stick with server side validation for now. Perhaps add client side later in the project.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
1. Use server-side validation (which you should do anyways, since the validators use javascript, and js may be disabled).
2. Write javascript to populate the day combo based on the month combo (I assume you're trying to eliminate Feb 31, etc). If you take this approach, you probably need to incorporate the year into the mix as well, to allow Feb 29.
3. Write js to perform custom validation. You need to use a CustomValidator control, and set the ClientValidationFunction property to your js validation function name.