473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Compiler disallows for loop in ASPX ... what's up?

Hi All,

[See below for history of posting this question]

In effort to write a loop in ASPX to generate a set of labels, I tried this:

<form id="Form2" method="post" runat="server">
<script language="C#" runat="server">
int nCols = 8;
int nRows = 20;
int iHeight = 25;
int iWidth = 50;
int iVertGap = 5;
int iHorGap = 5;
for (int iRow=0; iRow<nRows; iRow++) // "for"
flagged as an error by the compiler
{
<asp:Label ID="Lbl" RunAt="server" />
[snip]

intending to assign values to the properties of the Lbl object. But the
compiler announced:

CS1519: Invalid token 'for' in class, struct, or interface member
declaration

What can I do to generate a bunch of object programmatically in ASPX?

Thanks in advance,
Richard

I posted this first in microsoft.public.dotnet.framework.
Then thought it would be more appropriate in
microsoft.public.dotnet.framework.windowsforms
Then I received advice that it would be more appropriate in the newsgroups
listed abovel.
Nov 19 '05 #1
8 1590
You cant assign nested controls inline like in asp, you have to ctreate them
at run time add them to the forms collection or to a palceholder.

Label Label1 = New Label()
Label1.ID = "Label"

add it to the form

Form1.Controls.Add(Label1)

or add it to a placeholder

PlaceHolder1.Controls.Add(Label1);

You should create them in form load

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Richard Lionheart" <No***@Nowhere.net> wrote in message
news:eY*************@TK2MSFTNGP14.phx.gbl...
Hi All,

[See below for history of posting this question]

In effort to write a loop in ASPX to generate a set of labels, I tried
this:

<form id="Form2" method="post" runat="server">
<script language="C#" runat="server">
int nCols = 8;
int nRows = 20;
int iHeight = 25;
int iWidth = 50;
int iVertGap = 5;
int iHorGap = 5;
for (int iRow=0; iRow<nRows; iRow++) // "for"
flagged as an error by the compiler
{
<asp:Label ID="Lbl" RunAt="server" />
[snip]

intending to assign values to the properties of the Lbl object. But the
compiler announced:

CS1519: Invalid token 'for' in class, struct, or interface member
declaration

What can I do to generate a bunch of object programmatically in ASPX?

Thanks in advance,
Richard

I posted this first in microsoft.public.dotnet.framework.
Then thought it would be more appropriate in
microsoft.public.dotnet.framework.windowsforms
Then I received advice that it would be more appropriate in the newsgroups
listed abovel.

Nov 19 '05 #2
unlike asp, only methods, properties and fields are allowed to be defined in
a runat=server script block with asp.net. inline code is only allowed with
the <% %> syntax (which does not allow method declarations).

-- bruce (sqlwork.com)
"Richard Lionheart" <No***@Nowhere.net> wrote in message
news:eY*************@TK2MSFTNGP14.phx.gbl...
Hi All,

[See below for history of posting this question]

In effort to write a loop in ASPX to generate a set of labels, I tried
this:

<form id="Form2" method="post" runat="server">
<script language="C#" runat="server">
int nCols = 8;
int nRows = 20;
int iHeight = 25;
int iWidth = 50;
int iVertGap = 5;
int iHorGap = 5;
for (int iRow=0; iRow<nRows; iRow++) // "for"
flagged as an error by the compiler
{
<asp:Label ID="Lbl" RunAt="server" />
[snip]

intending to assign values to the properties of the Lbl object. But the
compiler announced:

CS1519: Invalid token 'for' in class, struct, or interface member
declaration

What can I do to generate a bunch of object programmatically in ASPX?

Thanks in advance,
Richard

I posted this first in microsoft.public.dotnet.framework.
Then thought it would be more appropriate in
microsoft.public.dotnet.framework.windowsforms
Then I received advice that it would be more appropriate in the newsgroups
listed abovel.

Nov 19 '05 #3
Dear Jim and Bruce,

Thanks for responding, and thanks for the facts ... though I'm bummed out.
I expected the fact that C# is embedded in ASP.NET would certainly allow for
programmers to escape repetative coding. C'est la vie.

Regards,
Richard Muller
Nov 19 '05 #4
Gentlemen,

I trying to create a matrix of labels on the server, cache the resulting
HTML, and let clients log in and download the generated web page.

Since I can't use "for", how about if I load the text destined for each
page into an Access 2003 or SQL Server 2000 database and executed a foreach
loop to access the text, dynamically create a Label object, assign the
relevant text and compute, then assign, the coordinates?

And I do all this in a PageLoad method?

Thanks in advance for any further consideration,
Richard Muller
"Richard Lionheart" <No***@Nowhere.net> wrote in message
news:eY*************@TK2MSFTNGP14.phx.gbl...
Hi All,

[See below for history of posting this question]

In effort to write a loop in ASPX to generate a set of labels, I tried
this:

<form id="Form2" method="post" runat="server">
<script language="C#" runat="server">
int nCols = 8;
int nRows = 20;
int iHeight = 25;
int iWidth = 50;
int iVertGap = 5;
int iHorGap = 5;
for (int iRow=0; iRow<nRows; iRow++) // "for"
flagged as an error by the compiler
{
<asp:Label ID="Lbl" RunAt="server" />
[snip]

intending to assign values to the properties of the Lbl object. But the
compiler announced:

CS1519: Invalid token 'for' in class, struct, or interface member
declaration

What can I do to generate a bunch of object programmatically in ASPX?

Thanks in advance,
Richard

I posted this first in microsoft.public.dotnet.framework.
Then thought it would be more appropriate in
microsoft.public.dotnet.framework.windowsforms
Then I received advice that it would be more appropriate in the newsgroups
listed abovel.

Nov 19 '05 #5
Have you read about datagrid or datalist controls. Once you have your data
you can bind this to a list/grid type control and the bind will
automatically create a table for you. Its immensly flexible.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Richard Lionheart" <No***@Nowhere.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Gentlemen,

I trying to create a matrix of labels on the server, cache the resulting
HTML, and let clients log in and download the generated web page.

Since I can't use "for", how about if I load the text destined for each
page into an Access 2003 or SQL Server 2000 database and executed a
foreach loop to access the text, dynamically create a Label object, assign
the relevant text and compute, then assign, the coordinates?

And I do all this in a PageLoad method?

Thanks in advance for any further consideration,
Richard Muller
"Richard Lionheart" <No***@Nowhere.net> wrote in message
news:eY*************@TK2MSFTNGP14.phx.gbl...
Hi All,

[See below for history of posting this question]

In effort to write a loop in ASPX to generate a set of labels, I tried
this:

<form id="Form2" method="post" runat="server">
<script language="C#" runat="server">
int nCols = 8;
int nRows = 20;
int iHeight = 25;
int iWidth = 50;
int iVertGap = 5;
int iHorGap = 5;
for (int iRow=0; iRow<nRows; iRow++) // "for"
flagged as an error by the compiler
{
<asp:Label ID="Lbl" RunAt="server" />
[snip]

intending to assign values to the properties of the Lbl object. But the
compiler announced:

CS1519: Invalid token 'for' in class, struct, or interface member
declaration

What can I do to generate a bunch of object programmatically in ASPX?

Thanks in advance,
Richard

I posted this first in microsoft.public.dotnet.framework.
Then thought it would be more appropriate in
microsoft.public.dotnet.framework.windowsforms
Then I received advice that it would be more appropriate in the
newsgroups listed abovel.


Nov 19 '05 #6
You're not thinking fourth-dimensionally, Richard! ;-)

Actually, you're not thinking object-oriented. In fact, OOP not only allows
for programmers to escape repetitive coding, but allows for much leaner
coding, and easier code maintenance and extensibility. OOP is hard to get
your head around at first, but once you "get it," it all falls neatly into
place, and is actually much easier to work with than procedural programming.
The difficulty in understanding OOP is due to the fact that OOP requires a
much more abstract way of looking at programming. I would strongly recommend
making the effort to get your head around how OOP works. You'll be glad you
did!

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Richard Lionheart" <No***@Nowhere.net> wrote in message
news:eX**************@TK2MSFTNGP11.phx.gbl...
Dear Jim and Bruce,

Thanks for responding, and thanks for the facts ... though I'm bummed out.
I expected the fact that C# is embedded in ASP.NET would certainly allow
for programmers to escape repetative coding. C'est la vie.

Regards,
Richard Muller

Nov 19 '05 #7
Hi John,
Have you read about datagrid or datalist controls.


No, I haven't.

I've just started playing with User Controls as a means of encapsulating
some of the code I need.

I just decided/realized that table is a better approach than a matrix of
labels.

I did find the foreach command, so I was heading in the direction of using
an Access DB and sucking in the content for my matrix.

I'll check out datagrid and datalist controls today.

Thanks for the guidance. I needed some high level direction.

Best wishes,
Richard
Nov 19 '05 #8
Hi Kevin,

Thanks for weighing in on my question.

I agree about the value of OOP and have had some experience in C++ business
applications. I'm just trying to get off the ground in this new (for me)
environment. As I said in news:uM***************@TK2MSFTNGP15.phx.gbl, in
response to John Timney's post this morning, I've had a few more thoughts
and will follow his suggestions.

I'm sure with the help of you guys I'll get launched in ASP.NET programming.

Best wishes,
Richard
Nov 19 '05 #9

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

Similar topics

13
by: Neil Zanella | last post by:
Hello, I wonder whether anyone has ever come across the following g++ compiler error message. I don't recall ever seeing it before. I solved my problem but I am still not sure about what this...
15
by: Mike Lansdaal | last post by:
I came across a reference on a web site (http://www.personalmicrocosms.com/html/dotnettips.html#richtextbox_lines ) that said to speed up access to a rich text box's lines that you needed to use a...
1
by: Karl Lang | last post by:
Hi I've created a new configuration section in Web.Config to hold the connection string for my database. If I have Option Strict On I get a message "Option Strict On disallows late binding" when I...
4
by: Heinz | last post by:
Hi all, I use VB.net 2003 and want to export data to Excel. Target PCs still have Office 2000 so I could not use Microsofts PIAs. Instead I use the included Excel 10 COM DLL from Microsoft....
7
by: Owen Mortensen | last post by:
(This code was working in asp.net 1.1 VS2003. After upgrade to VS2005, chokes): in the aspx file: <ItemTemplate> <asp:datagrid id="dg_instr" runat="server" AutoGenerateColumns="False"...
1
by: Adotek | last post by:
Hi All, I've just converted a solution from .Net v1.1 to v2.0, by allowing Visual Studio 2005 to do the conversion. Since doing so, I am getting a compilation error as follows: "Option...
5
by: cody | last post by:
Why doesn't the compiler give me any warning if it encounters code like the following: void foo() { // some code here // foo() ist not nested in a pre-condition loop, some if- or else- ...
7
by: Lynn | last post by:
Hello, I have a website that is working fine. I have just turned on "option strict" and am getting an error with the parts of my code. I have fixed everything but this section, which has me...
244
by: Ajinkya | last post by:
Can anyone suggest me a good compiler for(c/cpp) for windows? I tried dev cpp but its debugging facility is very poor.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...

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.