473,661 Members | 2,431 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I pass values to properties ? (eg StartYear='<%=D ateTime.Now.Yea r%>')

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='<%=D ateTime.Now.Yea r%>'
Runat="Server" />

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

I tried converting it like this ...

<ctls:fred id="frdFred"
StartYear='<%=C onvert.ToInt32( DateTime.Now.Ye ar)%>' Runat="Server" />

but got the same error.

Any ideas how I get around this? I thought DateTime.Now.Ye ar 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 2820
Alan, you must do this in code via fdrFred.StartYe ar = DaeTime.Now.Yea r

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Alan Silver" <al*********@no spam.thanx> wrote in message
news:U$******** ******@nospamth ankyou.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='<%=D ateTime.Now.Yea r%>'
Runat="Server" />

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

I tried converting it like this ...

<ctls:fred id="frdFred"
StartYear='<%=C onvert.ToInt32( DateTime.Now.Ye ar)%>' Runat="Server" />

but got the same error.

Any ideas how I get around this? I thought DateTime.Now.Ye ar 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.StartYe ar = DaeTime.Now.Yea r

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*********@no spam.thanx> wrote in message
news:VO******** ******@nospamth ankyou.spam...
Alan, you must do this in code via fdrFred.StartYe ar = DaeTime.Now.Yea r


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
1878
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" method="GET"> <p>Name: <input type="text" name="name">
2
1968
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") objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source =c:\access\mydb.mdb") %>
6
4721
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 saved in seperate file and all my subclasses and parent class are placed in the same folder. The parent class is subclass of wx.Frame, and subclasses are subclass of wx.Panel. Each subclass will create a GUI for each task..
5
13668
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 “a” and “b”, need pass them to Function A. Please help me on How to make this happen? Should I pass values of “a” and “b” to C, then to C, to B, finally to A?
3
1201
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 same page .. can anyone help ?? thnxs in advance
2
1343
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 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 same page .. can anyone help ?? thnxs in advance
15
1378
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 original objects in the calling function. Does this mean there is not pass-values calling to a function in
6
1694
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; using System.Collections.Generic; using System.Text;
0
1297
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
2856
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" runat="server" HorizontalAlign="Center" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="SchedName" HeaderText="SchedName" ...
0
8432
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
8343
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,...
1
8545
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
7364
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...
0
5653
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
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.