473,795 Members | 2,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:CompareVal idator id="CompareVali dator1" style="Z-INDEX: 103; LEFT:
431px; POSITION: absolute; TOP: 277px" runat="server"
ErrorMessage="C ompareValidator " ControlToValida te="TextBox2" Type="Date"
Operator="Great erThanEqual" ValueToCompare= "now()"></asp:CompareVali dator>
Nov 16 '05 #1
4 12503
probably you'll have to set the ValueToCompare in the code...
Page_load
{
CompareValidato r1.ValueToCompa re = DateTime.Now;
}

cheers,
mortb

"Stephen" <St*****@discus sions.microsoft .com> wrote in message
news:4C******** *************** ***********@mic rosoft.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:CompareVal idator id="CompareVali dator1" style="Z-INDEX: 103; LEFT:
431px; POSITION: absolute; TOP: 277px" runat="server"
ErrorMessage="C ompareValidator " ControlToValida te="TextBox2" Type="Date"
Operator="Great erThanEqual" ValueToCompare= "now()"></asp:CompareVali dator>

Nov 16 '05 #2
I tried this but got the following error.
Cannot implicitly convert type 'System.DateTim e' 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
{
CompareValidato r1.ValueToCompa re = DateTime.Now;
}

cheers,
mortb

"Stephen" <St*****@discus sions.microsoft .com> wrote in message
news:4C******** *************** ***********@mic rosoft.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:CompareVal idator id="CompareVali dator1" style="Z-INDEX: 103; LEFT:
431px; POSITION: absolute; TOP: 277px" runat="server"
ErrorMessage="C ompareValidator " ControlToValida te="TextBox2" Type="Date"
Operator="Great erThanEqual" ValueToCompare= "now()"></asp:CompareVali dator>


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

public bool Validate(string source)
{
DateTimeFormatI nfo fi = new DateTimeFormatI nfo();
fi = DateTimeFormatI nfo.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*****@discus sions.microsoft .com> wrote in message
news:6C******** *************** ***********@mic rosoft.com...
I tried this but got the following error.
Cannot implicitly convert type 'System.DateTim e' 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
{
CompareValidato r1.ValueToCompa re = DateTime.Now;
}

cheers,
mortb

"Stephen" <St*****@discus sions.microsoft .com> wrote in message
news:4C******** *************** ***********@mic rosoft.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:CompareVal idator id="CompareVali dator1" style="Z-INDEX: 103; LEFT:
> 431px; POSITION: absolute; TOP: 277px" runat="server"
> ErrorMessage="C ompareValidator " ControlToValida te="TextBox2"
> Type="Date"
> Operator="Great erThanEqual"
> ValueToCompare= "now()"></asp:CompareVali dator>


Nov 16 '05 #4
Hi,

For example, what I did was set:

<asp:compareval idator id="cvEndDate" style="Z-INDEX: 229; LEFT: 592px; POSITION: absolute; TOP: 1896px"
runat="server" Font-Names="Arial" Font-Size="X-Small"
ControlToValida te="txtEndDate "
ErrorMessage="E nd Date must be after start date" Type="Date" Operator="Great erThan"
ControlToCompar e="txtStartDate ">
End Date must be after start date
</asp:comparevali dator>

in Page_Load:

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

txtCurrDate.Tex t = DateTime.Now.To ShortDateString ();
txtStartDate.Te xt = StartDateCalend ar.SelectedDate .ToShortDateStr ing();
txtEndDate.Text = EndDateCalendar .SelectedDate.T oShortDateStrin g();
and everytime, the calendar control (or whatever you have that causes the date to change) has a
selectedIndexCh anged 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)
{
DateTimeFormatI nfo fi = new DateTimeFormatI nfo();
fi = DateTimeFormatI nfo.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*****@discus sions.microsoft .com> wrote in message
news:6C******* *************** ************@mi crosoft.com...
I tried this but got the following error.
Cannot implicitly convert type 'System.DateTim e' 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
{
CompareValidato r1.ValueToCompa re = DateTime.Now;
}

cheers,
mortb

"Stephen" <St*****@discus sions.microsoft .com> wrote in message
news:4C******** *************** ***********@mic rosoft.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:CompareVal idator id="CompareVali dator1" style="Z-INDEX: 103; LEFT:
> 431px; POSITION: absolute; TOP: 277px" runat="server"
> ErrorMessage="C ompareValidator " ControlToValida te="TextBox2"
> Type="Date"
> Operator="Great erThanEqual"
> ValueToCompare= "now()"></asp:CompareVali dator>


Nov 16 '05 #5

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

Similar topics

30
3697
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 seems unnecessarily long. For some while, the following approach has been given here :- function ValidDate(y, m, d) { // m = 0..11 ; y m d integers, y!=0
0
1996
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 accept on an insert, however, when it does a comparision validation it is failing. I have StartDate = comparing to an invisible textbox that contains todays date EndDate = comparing to StartDate needing to be >= SetupDate = comparing to StartDate...
7
10311
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 cannot preceed the start date. How can I perform the necessary validation using the least number of validation controls. For example is it necessary that I add a requiredfieldvalidator for the start date field and end date field to make sure a value...
7
31845
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 current date. If not, I'd like to display the error message to ValidationSummary. It seems to make sense to me to use CompareValidator but the problem is put the current date into CompareValidator. So, I created a hidden text field in my aspx. ...
12
3291
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 Thanks, Diego.
1
4704
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. <asp:RangeValidator id="varngRollCallDate" runat="server" ErrorMessage="Please enter a valid date in 'dd/mm/yyyy' format." ControlToValidate="txtDate" Display="Dynamic" Type="Date" MinimumValue="01/01/2006" MaximumValue="31/12/2006"...
17
5286
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
2856
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 well. So the control should validate the typed values on the fly. Is it possible?
2
6744
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 I' using the leave event. Right now I am creating a 'leave' sub for each of the fields. However, I'd like to simplify that and just call the name of a function and plug the field name as a variable and be done. In other words, I would like...
5
3447
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 call it. It was suggested to be to have it run through an if statement and if the user enters an invalid date it will kick them to an error page. Here is the date validation code. // date validation using SimpleDateFormat // it will take a...
0
9673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9044
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.