471,310 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 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 1758
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by tshad | last post: by
3 posts views Thread by Joey | last post: by
2 posts views Thread by Tarun Mistry | last post: by
3 posts views Thread by Darrel | last post: by
reply views Thread by Toco | last post: by
reply views Thread by beasers | last post: by
reply views Thread by rosydwin | last post: by

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.