CompareValidator and Todays Date

Posted on 2004-04-12
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.
Question by:dwcorwith
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
LVL 44

Expert Comment

ID: 10806200
you might try:

Dim static strToday as String = Date.Today.ToShortDateString


Accepted Solution

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,

Author Comment

ID: 10808264
After respelling CompareValidator1 it works great!  

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why use this lambda? 12 96
Error import assembly 19 30
sql connection error null reference exception 9 29
ASP.NET VB code for check and insert in a table 4 45
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 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