472,952 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Range Validator - Newby - Help:)

Hi - I was hoping to use the range validator to check that the user's age is
between 10 & 65 based upon an entered DOB. I thought I could use max&min date
variables in the Validator & have those populated in the page_load event
based on today's date. Dead end so far. Please HELP! Many thanks ... c
Jul 31 '08 #1
5 1816
Chris D wrote:
Hi - I was hoping to use the range validator to check that the user's age is
between 10 & 65 based upon an entered DOB. I thought I could use max&min date
variables in the Validator & have those populated in the page_load event
based on today's date.
Yes, that sounds plausible.
Dead end so far. Please HELP! Many thanks ... c
Well, what did you try?

--
Göran Andersson
_____
http://www.guffa.com
Aug 1 '08 #2
Hi Goran & thanks for helping. This is what I have ...
protected void Page_Load(object sender, EventArgs e)
{
DateTime theDate, maxDate, minDate;
theDate = DateTime.Parse(DateTime.Now);
minDate = theDate.AddYears(-65);
maxDate = theDate.AddYears(-10);
}

And this in the aspx
<asp:TextBox ID="tbDOBchk" runat="server"></asp:TextBox>
<asp:RangeValidator ID="rvDOBchk" Type="Date" runat="server"
ControlToValidate="tbDOBchk" ErrorMessage="RangeValidator"
MaximumValue="maxDate"
MinimumValue="minDate">message</asp:RangeValidator>


"Göran Andersson" wrote:
Chris D wrote:
Hi - I was hoping to use the range validator to check that the user's age is
between 10 & 65 based upon an entered DOB. I thought I could use max&min date
variables in the Validator & have those populated in the page_load event
based on today's date.

Yes, that sounds plausible.
Dead end so far. Please HELP! Many thanks ... c

Well, what did you try?

--
Göran Andersson
_____
http://www.guffa.com
Aug 1 '08 #3
Chris D wrote:
Hi Goran & thanks for helping. This is what I have ...
protected void Page_Load(object sender, EventArgs e)
{
DateTime theDate, maxDate, minDate;
theDate = DateTime.Parse(DateTime.Now);
The DateTime.Now property returns a DateTime value, so you should not
parse it. By doing so you force an implicit conversion to string, which
you then parse into a DateTime value identical to the one that
DateTime.Now returned.

theDate = DateTime.Now.

However, for your application the time is irrelevant, so you would
rather use the Today property:

theDate = DateTime.Today;
minDate = theDate.AddYears(-65);
maxDate = theDate.AddYears(-10);
}

And this in the aspx
<asp:TextBox ID="tbDOBchk" runat="server"></asp:TextBox>
<asp:RangeValidator ID="rvDOBchk" Type="Date" runat="server"
ControlToValidate="tbDOBchk" ErrorMessage="RangeValidator"
MaximumValue="maxDate"
MinimumValue="minDate">message</asp:RangeValidator>
You can't use variable names as property values. The control parses the
arguments, it doesn't evaluate them.

You should set the arguments from the Page_Load method:

rvDOBchk.MinimumValue = minDate;
rvDOBchk.MAximumValue = maxDate;

--
Göran Andersson
_____
http://www.guffa.com
Aug 1 '08 #4
Göran Andersson wrote:
Chris D wrote:
>Hi Goran & thanks for helping. This is what I have ...
protected void Page_Load(object sender, EventArgs e)
{
DateTime theDate, maxDate, minDate;
theDate = DateTime.Parse(DateTime.Now);

The DateTime.Now property returns a DateTime value, so you should not
parse it. By doing so you force an implicit conversion to string, which
you then parse into a DateTime value identical to the one that
DateTime.Now returned.

theDate = DateTime.Now.

However, for your application the time is irrelevant, so you would
rather use the Today property:

theDate = DateTime.Today;
> minDate = theDate.AddYears(-65);
maxDate = theDate.AddYears(-10);
}

And this in the aspx
<asp:TextBox ID="tbDOBchk" runat="server"></asp:TextBox>
<asp:RangeValidator ID="rvDOBchk" Type="Date"
runat="server" ControlToValidate="tbDOBchk" ErrorMessage="RangeValidator"
MaximumValue="maxDate"
MinimumValue="minDate">message</asp:RangeValidator>

You can't use variable names as property values. The control parses the
arguments, it doesn't evaluate them.
Also, the variables are local in the Page_Load method, so you would not
be able to reach them from the markup code.

Also, the Page_Load method runs after the markup is parsed, so even if
you could reach the variables, their values would not yet have been set.

So, in conclusion, the unreachable variables that you did not use
doesn't exist yet. ;)
You should set the arguments from the Page_Load method:

rvDOBchk.MinimumValue = minDate;
rvDOBchk.MAximumValue = maxDate;

--
Göran Andersson
_____
http://www.guffa.com
Aug 1 '08 #5
Huge thanks Goran. I learned a whole lot from you!!!

"Göran Andersson" wrote:
Göran Andersson wrote:
Chris D wrote:
Hi Goran & thanks for helping. This is what I have ...
protected void Page_Load(object sender, EventArgs e)
{
DateTime theDate, maxDate, minDate;
theDate = DateTime.Parse(DateTime.Now);
The DateTime.Now property returns a DateTime value, so you should not
parse it. By doing so you force an implicit conversion to string, which
you then parse into a DateTime value identical to the one that
DateTime.Now returned.

theDate = DateTime.Now.

However, for your application the time is irrelevant, so you would
rather use the Today property:

theDate = DateTime.Today;
minDate = theDate.AddYears(-65);
maxDate = theDate.AddYears(-10);
}

And this in the aspx
<asp:TextBox ID="tbDOBchk" runat="server"></asp:TextBox>
<asp:RangeValidator ID="rvDOBchk" Type="Date"
runat="server" ControlToValidate="tbDOBchk" ErrorMessage="RangeValidator"
MaximumValue="maxDate"
MinimumValue="minDate">message</asp:RangeValidator>
You can't use variable names as property values. The control parses the
arguments, it doesn't evaluate them.

Also, the variables are local in the Page_Load method, so you would not
be able to reach them from the markup code.

Also, the Page_Load method runs after the markup is parsed, so even if
you could reach the variables, their values would not yet have been set.

So, in conclusion, the unreachable variables that you did not use
doesn't exist yet. ;)
You should set the arguments from the Page_Load method:

rvDOBchk.MinimumValue = minDate;
rvDOBchk.MAximumValue = maxDate;


--
Göran Andersson
_____
http://www.guffa.com
Aug 1 '08 #6

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

Similar topics

1
by: tshad | last post by:
I have been trying to set up a range validator and regular expression for my dates. I tried this: <asp:RangeValidator runat="server" ControlToValidate="AbsentFrom1" MinimumValue="12/31/1950"...
3
by: Joey | last post by:
I have a page with a range validator on it. I have the following set... ControlToValidate=txtSomeTextBox MinimumValue=1 MaximumValue=2000 Now, when I run the form, the values 1,2,10 all pass...
1
by: MattB | last post by:
I have a page with dual controls for a person to enter their height and weight. The dual controls are for English and metric units, and Javascript onChange events handle populating the other...
2
by: Tarun Mistry | last post by:
Hi everyone, i have a range validator set to date mode. However, I want the max date to be whatever it is right now, is there a way of setting this within the properties of the range validator? ...
3
by: Darrel | last post by:
I have this range validator: <asp:rangevalidator id=RngVal_LGwidth runat="server" ErrorMessage="LG Width needs to be between 10px and 2000px" EnableClientScript="False"...
0
by: Toco | last post by:
Hello. I have two calendar controls and wish to validate the timespan difference between them. Can this be accomplished using a range validator? Currently I'm validating the timespan on the...
0
by: beasers | last post by:
Hi I can't find any other examples of this, but I have a simple text box with an accompanying range validator set to Min 0 and Max 99999. The validation works if I enter an illegal character...
15
by: chicane | last post by:
I am using VS2008 and I trying to use the Range Validator for the following: I have a text box that a user will input a date into for an appointment - the date entered must be at least 7 days...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.