CompareValidator with Dates

T

THaskell

I am using a comparevalidator to make sure that a date for a scheduling
app is not in the past.

<asp:CompareValidator id="cvSD" runat="server"
ControlToValidate="txtStartDate"
ErrorMessage="Dates cannot be in the past."
Display="Static"
Operator="GreaterThanEqual"
Type="Date" />

When the page is loaded I set the ValueToCompare of the validator to
DateTime.Now.Date. The validator will throw an error for some dates in
the future but not others. For example, today is 10/7 then 10/8 and
10/9 are valid but it throws the error for 10/10 - 10/31. 11/1 - 11/9
will be valid but 11/10 - 11/30 will cause an error, and so on.

Thanks. Any help will be much appreciated, this is very confusing.
 
M

Mr Newbie

I just tried this and it works OK on my machine. I assume you are putting
in the full date, such as 10/10/2005 ?

Could this perhaps be some mismatch between the locale on your machine and
the one on the server ( if they are different )

Regards Mr N
 
T

THaskell

Yes, I am using the full date. Could you explain more about the
mismatch? You are saying that if the date on the server is different
from the date on my computer then it will not validate properly? what
about if the time is different?
 
M

Mr Newbie

I'm guessing here really but . . .

The validators on the client side are Javascript functions and I assume that
they must use locale information to be able to compare dates, unless they
can detect the locale on the local machine and adjust which scripts to use.
Or perhaps the scripts themselves do this Im not sure.

An american date 11/01/2005 is the same as a UK date 01/11/2005

However, from your description, it would not seem this is the case, so Im
not really sure except that it works on my machine here where I know the
locale is the same on client and server.

Hope this may help is some small way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top