Solved

CompareValidator and Todays Date

Posted on 2004-04-12
3
4,115 Views
Last Modified: 2012-08-14
Hi Experts:
I am trying to compare a textbox field to todays date so that the user can not enter something less than today.

Dim static strToday as String = CStr(Today)

<asp:CompareValidator Runat=server ID= CompareValidator1 ErrorMessage="Date must be AFTER Today" ControlToValidate = "txtStartDate" ValueToCompare="strToday" Type=Date></asp:CompareValidator>

This gives error:
The value 'strToday' of the ValueToCompare property of 'CompareValidator1' cannot be converted to type 'Date'.

I am fairly sure it is because strToday = #4/12/2004# and the # need to be stripped off.  Do I need to create a function to strip this off?  There must be an easier way.
cheers,
dwc
0
Comment
Question by:dwcorwith
3 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
Comment Utility
you might try:

Dim static strToday as String = Date.Today.ToShortDateString


AW
0
 
LVL 7

Accepted Solution

by:
dante469 earned 200 total points
Comment Utility
ValueToCompare= refs to a constant not a variable.....

Please try this....

.aspx page---->

<asp:CompareValidator Runat=server ID="CompareValidator1" ErrorMessage="Date must be AFTER Today" ControlToValidate = "txtStartDate" ValueToCompare="1/1/1980" Type=Date></asp:CompareValidator>

codebehind on load--->

CampareValidator1.ValueToCompare = today

Have Fun,
dante
0
 
LVL 2

Author Comment

by:dwcorwith
Comment Utility
Dante,
After respelling CompareValidator1 it works great!  
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now