473,461 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do I pass values to properties ? (eg StartYear='<%=DateTime.Now.Year%>')

Hello,

I have a user control that has a property StartYear. Logically enough,
this takes an Int32 value. I have no problem doing something like ...

<ctls:fred id="frdFred" StartYear="2000" Runat="Server" />

but if I try ...

<ctls:fred id="frdFred" StartYear='<%=DateTime.Now.Year%>'
Runat="Server" />

I get an error "Cannot create an object of type System.Int32 from its
string representation '<%=DateTime.Now.Year%>' for the StartYear
property".

I tried converting it like this ...

<ctls:fred id="frdFred"
StartYear='<%=Convert.ToInt32(DateTime.Now.Year)%> ' Runat="Server" />

but got the same error.

Any ideas how I get around this? I thought DateTime.Now.Year returned an
Int32, so I have no idea why it thinks it's a string.

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #1
4 2811
Alan, you must do this in code via fdrFred.StartYear = DaeTime.Now.Year

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:U$**************@nospamthankyou.spam...
Hello,

I have a user control that has a property StartYear. Logically enough,
this takes an Int32 value. I have no problem doing something like ...

<ctls:fred id="frdFred" StartYear="2000" Runat="Server" />

but if I try ...

<ctls:fred id="frdFred" StartYear='<%=DateTime.Now.Year%>'
Runat="Server" />

I get an error "Cannot create an object of type System.Int32 from its
string representation '<%=DateTime.Now.Year%>' for the StartYear
property".

I tried converting it like this ...

<ctls:fred id="frdFred"
StartYear='<%=Convert.ToInt32(DateTime.Now.Year)%> ' Runat="Server" />

but got the same error.

Any ideas how I get around this? I thought DateTime.Now.Year returned an
Int32, so I have no idea why it thinks it's a string.

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 19 '05 #2
>Alan, you must do this in code via fdrFred.StartYear = DaeTime.Now.Year

That's a pain. Is there any reason why I can't do it in the tag?

Thanks for the reply.

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #3
i believe it's a timing issue. The server control is parsed and turned into
an object (so that you can do nice things in codebehind) well before asp.net
parses <%= %> so the it sees <%= %> as an actual literla value. It really
isn't a pain, it helps improve readability and maintainability... If you
are going to hard code a value, you should do so in the usercontrol....not
the instantiator..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:VO**************@nospamthankyou.spam...
Alan, you must do this in code via fdrFred.StartYear = DaeTime.Now.Year


That's a pain. Is there any reason why I can't do it in the tag?

Thanks for the reply.

--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 19 '05 #4
>i believe it's a timing issue. The server control is parsed and turned into
an object (so that you can do nice things in codebehind) well before asp.net
parses <%= %> so the it sees <%= %> as an actual literla value. It really
isn't a pain, it helps improve readability and maintainability... If you
are going to hard code a value, you should do so in the usercontrol....not
the instantiator..


Yeah but sometimes you want to pass default values in which will vary
from tag to tag, and it's just convenient to do that in the tag. For
example, I have just finished a control to show the date and time as
five drop downs. On the page where I used it, some of the instances of
it want the year range to be the last five, some need it to be the next
five. I know they can easily be done in the code, it just seemed easier
to put the values with the tag.

I guess it's just a case of getting into a new way of thinking. Thanks
for the reply.

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #5

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

Similar topics

7
by: Matthew Lasar | last post by:
I am trying to study php from a book. But the code doesn't seem to work for me. I set up a form, as follows: <html> <head> <title>form</title> </head> <body> <form action="results.php"...
2
by: Ben | last post by:
Hi, When clicking on a button, a new record must be created in an Access table. See my code: <% set objdc = Server.CreateObject("ADODB.Connection")...
6
by: kath | last post by:
hi everyone......... I have a task, I have fragmented the task into subtask. I have planned to create a class to each subclass and one parent class to handle the sub tasks. Each subclass are...
5
by: codercoder | last post by:
Hello Helpers, I have a question about passing values through multiple C++ functions: Function A calls function B; Function B calls function C; Function C calls function D; D has two values...
3
by: Prashant P | last post by:
help in asp.net to pass values from a page to a frame inside the same page!!! i call values 4m a database on a click of a button , den that values r supposed to be displayed in a frame dats in the...
2
by: Prashant P | last post by:
help in asp.net to pass values from a page to a frame inside the same page -------------------------------------------------------------------------------- help in asp.net to pass values from a...
15
by: J. Peng | last post by:
Hello, I saw this statement in Core Python Programming book, All arguments of function calls are made by reference, meaning that any changes to these parameters within the function affect the...
6
by: =?Utf-8?B?Unlhbg==?= | last post by:
I am trying to pass a value from a texbox in Form1 to a textbox in Form2 using properties in VS2005 but it doesn't work; please help (project is attached). Code for Game Class: using System;...
0
by: Aniket sonmale | last post by:
i need to pass values to a query in my shell script. my file will contain data as below. 3123213 1234133 4423434 4242343 .
2
by: dougancil | last post by:
I have a page with a gridview and I want to pass the value when a user clicks on a hyperlinked field in the grid to another page. Here is the code for the gridview: <asp:GridView ID="GridView1"...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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,...
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,...
0
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...
0
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...
0
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.