Solved

CompareValidator and Todays Date

Posted on 2004-04-12
3
4,136 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10806200
you might try:

Dim static strToday as String = Date.Today.ToShortDateString


AW
0
 
LVL 7

Accepted Solution

by:
dante469 earned 200 total points
ID: 10807663
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
ID: 10808264
Dante,
After respelling CompareValidator1 it works great!  
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

624 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