?
Solved

Custom validation of date when DropDown Lists are used

Posted on 2005-04-27
6
Medium Priority
?
356 Views
Last Modified: 2006-11-18
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?
0
Comment
Question by:gilkesy
  • 3
  • 3
6 Comments
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 13878120
You've got a few choices here...
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.
0
 

Author Comment

by:gilkesy
ID: 13878476
Well I was thinking something along the lines of this:

        If IsDate(dropDOBDD.SelectedValue & "/" & dropDOBMM.SelectedValue & "/" & dropDOBYY.SelectedValue) = False Then
            DOBValidator.Text = "Invalid Date"
            e.IsValid = False
        Else
            e.IsValid = True
            Session("DOB") = CDate(dropDOBDD1.SelectedValue & "/" & dropDOBMM1.SelectedValue & "/" & dropDOBYY1.SelectedValue)
        End If

0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 13878526
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.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:gilkesy
ID: 13879332
I'm going to stick with server side validation for now. Perhaps add client side later in the project.
0
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 500 total points
ID: 13879428
You could clean up your code just a bit by doing this:

dim stringDate as string = dropDOBDD.SelectedValue & "/" & dropDOBMM.SelectedValue & "/" & dropDOBYY.SelectedValue
e.isvalid = isdate(stringdate)
if e.isvalid then
  Session("DOB") = CDate(stringDate)
  DOBValidator.Text = ""
else
  DOBValidator.Text = "Invalid Date"
end if
0
 

Author Comment

by:gilkesy
ID: 13879446
Thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Integration Management Part 2
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question