473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Date Validation

Is there any way of using a compare validator to compare a textbox to see if
the date is greater than or equal to todays date. I want to set the
ValueToCompare property to now(). It doesn't seem to like this is there any
way around this problem

<asp:CompareValidator id="CompareValidator1" style="Z-INDEX: 103; LEFT:
431px; POSITION: absolute; TOP: 277px" runat="server"
ErrorMessage="CompareValidator" ControlToValidate="TextBox2" Type="Date"
Operator="GreaterThanEqual" ValueToCompare="now()"></asp:CompareValidator>
Nov 16 '05 #1
4 12475
probably you'll have to set the ValueToCompare in the code...
Page_load
{
CompareValidator1.ValueToCompare = DateTime.Now;
}

cheers,
mortb

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
Is there any way of using a compare validator to compare a textbox to see
if
the date is greater than or equal to todays date. I want to set the
ValueToCompare property to now(). It doesn't seem to like this is there
any
way around this problem

<asp:CompareValidator id="CompareValidator1" style="Z-INDEX: 103; LEFT:
431px; POSITION: absolute; TOP: 277px" runat="server"
ErrorMessage="CompareValidator" ControlToValidate="TextBox2" Type="Date"
Operator="GreaterThanEqual" ValueToCompare="now()"></asp:CompareValidator>

Nov 16 '05 #2
I tried this but got the following error.
Cannot implicitly convert type 'System.DateTime' to 'string'
Is there anyway of setting the Value to compare property in the Javascript??
If not do you know how I get rid of this build error

"mortb" wrote:
probably you'll have to set the ValueToCompare in the code...
Page_load
{
CompareValidator1.ValueToCompare = DateTime.Now;
}

cheers,
mortb

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
Is there any way of using a compare validator to compare a textbox to see
if
the date is greater than or equal to todays date. I want to set the
ValueToCompare property to now(). It doesn't seem to like this is there
any
way around this problem

<asp:CompareValidator id="CompareValidator1" style="Z-INDEX: 103; LEFT:
431px; POSITION: absolute; TOP: 277px" runat="server"
ErrorMessage="CompareValidator" ControlToValidate="TextBox2" Type="Date"
Operator="GreaterThanEqual" ValueToCompare="now()"></asp:CompareValidator>


Nov 16 '05 #3
I use the following code:

public bool Validate(string source)
{
DateTimeFormatInfo fi = new DateTimeFormatInfo();
fi = DateTimeFormatInfo.CurrentInfo;
DateTime dt = DateTime.Parse(source,fi);
return true;
}

However, this depends on the Regional Settings specified in your Control
Panel.

HTH

B Vidyadhar Joshi

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:6C**********************************@microsof t.com...
I tried this but got the following error.
Cannot implicitly convert type 'System.DateTime' to 'string'
Is there anyway of setting the Value to compare property in the
Javascript??
If not do you know how I get rid of this build error

"mortb" wrote:
probably you'll have to set the ValueToCompare in the code...
Page_load
{
CompareValidator1.ValueToCompare = DateTime.Now;
}

cheers,
mortb

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
> Is there any way of using a compare validator to compare a textbox to
> see
> if
> the date is greater than or equal to todays date. I want to set the
> ValueToCompare property to now(). It doesn't seem to like this is there
> any
> way around this problem
>
> <asp:CompareValidator id="CompareValidator1" style="Z-INDEX: 103; LEFT:
> 431px; POSITION: absolute; TOP: 277px" runat="server"
> ErrorMessage="CompareValidator" ControlToValidate="TextBox2"
> Type="Date"
> Operator="GreaterThanEqual"
> ValueToCompare="now()"></asp:CompareValidator>


Nov 16 '05 #4
Hi,

For example, what I did was set:

<asp:comparevalidator id="cvEndDate" style="Z-INDEX: 229; LEFT: 592px; POSITION: absolute; TOP: 1896px"
runat="server" Font-Names="Arial" Font-Size="X-Small"
ControlToValidate="txtEndDate"
ErrorMessage="End Date must be after start date" Type="Date" Operator="GreaterThan"
ControlToCompare="txtStartDate">
End Date must be after start date
</asp:comparevalidator>

in Page_Load:

StartDateCalendar.SelectedDate = StartDateCalendar.TodaysDate;
EndDateCalendar.SelectedDate = StartDateCalendar.SelectedDate.AddYears(1).AddDays (-1); //my default end
date was one year and a day less than my start date

txtCurrDate.Text = DateTime.Now.ToShortDateString();
txtStartDate.Text = StartDateCalendar.SelectedDate.ToShortDateString() ;
txtEndDate.Text = EndDateCalendar.SelectedDate.ToShortDateString();
and everytime, the calendar control (or whatever you have that causes the date to change) has a
selectedIndexChanged event, you'll have to update the text boxes with the up-to-date value.

Hope that helps,

Michelle Hlaing

Microsoft Support Professional

***Disclaimer: This posting is provided "as is" with no warranties and confers no rights.***
I use the following code:

public bool Validate(string source)
{
DateTimeFormatInfo fi = new DateTimeFormatInfo();
fi = DateTimeFormatInfo.CurrentInfo;
DateTime dt = DateTime.Parse(source,fi);
return true;
}

However, this depends on the Regional Settings specified in your Control
Panel.

HTH

B Vidyadhar Joshi

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:6C**********************************@microso ft.com...
I tried this but got the following error.
Cannot implicitly convert type 'System.DateTime' to 'string'
Is there anyway of setting the Value to compare property in the
Javascript??
If not do you know how I get rid of this build error

"mortb" wrote:
probably you'll have to set the ValueToCompare in the code...
Page_load
{
CompareValidator1.ValueToCompare = DateTime.Now;
}

cheers,
mortb

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
> Is there any way of using a compare validator to compare a textbox to
> see
> if
> the date is greater than or equal to todays date. I want to set the
> ValueToCompare property to now(). It doesn't seem to like this is there
> any
> way around this problem
>
> <asp:CompareValidator id="CompareValidator1" style="Z-INDEX: 103; LEFT:
> 431px; POSITION: absolute; TOP: 277px" runat="server"
> ErrorMessage="CompareValidator" ControlToValidate="TextBox2"
> Type="Date"
> Operator="GreaterThanEqual"
> ValueToCompare="now()"></asp:CompareValidator>


Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
0
by: Brian Conway | last post by:
I am having some validation and insertion problems. I am using a date picker that takes the selected date and puts it to ("dd-MMM-yyyy") format, as this was the only format that Oracle would...
7
by: Paul | last post by:
Hi, I have a form where a user is required to enter a start date and an end date. Both are required and must between a specific date range (e.g. 01/01/1900 and 01/01/2099) and the end date...
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
12
by: Diego | last post by:
Can I validate (possibly with a compare validator) a Date entered by the user based upon his regional settings? I.e. if a user is american the format would be mm/dd/yyyy, if brittish dd/mm/yyyy...
1
by: Brendan Reynolds | last post by:
In an ASP.NET 1.1 app I have the following range validation control. This is an intranet app that will be used only within Ireland, so all date input is expected to be in dd/mm/yyyy format. ...
17
by: Petyr David | last post by:
Just looking for the simplest. right now my perl script returns an error messge to the user if the date string is invalid. would like to do this before accessing the server. TX
3
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
I have VS 2005 (C#) There is a control numericUpDown so you can spin numeric values. What I need to do is to spin date (+- one day). How to do that? Moreover, I want a user to type the date as...
2
by: John Smith | last post by:
Hello, I have a VB.NET application with a Windows form that have several textboxes fields where I have dates entered. I would like to do a date validation check after the the field is updated, so...
5
Stang02GT
by: Stang02GT | last post by:
I have been asked to validate a date on our web-page so that people cannot enter dates like 14/1/08 or 2/30/06. I have found code that will do exactly what i need it to do, but i am not sure how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.