?
Solved

CompareValidator and Todays Date

Posted on 2004-04-12
3
Medium Priority
?
4,143 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 800 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

Google Certified Professional - Cloud Architect

This course (1 of 3) is designed to help students who are interested in Google Cloud Platform (GCP) to become familiar with the platform, navigate the console and learn its capabilities. It will also prepare students for the Google Cloud Architect certification exam.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

719 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