473,385 Members | 1,912 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,385 software developers and data experts.

aspx variable replacement - runat=server

Hello

How do I perform a variable replacement in ASP.NET when I am using the
runat=server clause to generate a table - it was simple in ASP

With ASP :
----------
<HTML>
....
<BODY>
....
<TABLE...>
<TR>
<TD colspan="<%=NumberOfCols%>">...<TD>
....
<TR>
....
<TABLE>
....
</BODY>
</HTML>

With ASP.NET :
--------------
<HTML>
....
<BODY>
....
<asp:Table... runat=server>
<asp:TableRow runat=server>
<asp:TableCell ColumnSpan="<%=NumberOfCols%>"
runat=server>...</asp:TableCell>
....
</asp:TableRow>
....
</asp:Table>
....
</BODY>
</HTML>

Then the Code Behind contains
....
Protected NumberOfCols As Integer = 6
....
But executing the above <%=NumberOfCols%> is not a valid value for
Int32.

However if I print the variable by placing <%=NumberOfCols%> somewhere
within the body of the html it prints the value of it ("6") correctly.
Can anyone help ?

Cheers
Phil

Nov 19 '05 #1
3 1842
Phil,

Try to remove the quotes:

ColumnSpan=<%=NumberOfCols%>

Eliyahu

<te*******@skunkbox.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hello

How do I perform a variable replacement in ASP.NET when I am using the
runat=server clause to generate a table - it was simple in ASP

With ASP :
----------
<HTML>
...
<BODY>
...
<TABLE...>
<TR>
<TD colspan="<%=NumberOfCols%>">...<TD>
...
<TR>
...
<TABLE>
...
</BODY>
</HTML>

With ASP.NET :
--------------
<HTML>
...
<BODY>
...
<asp:Table... runat=server>
<asp:TableRow runat=server>
<asp:TableCell ColumnSpan="<%=NumberOfCols%>"
runat=server>...</asp:TableCell>
...
</asp:TableRow>
...
</asp:Table>
...
</BODY>
</HTML>

Then the Code Behind contains
...
Protected NumberOfCols As Integer = 6
...
But executing the above <%=NumberOfCols%> is not a valid value for
Int32.

However if I print the variable by placing <%=NumberOfCols%> somewhere
within the body of the html it prints the value of it ("6") correctly.
Can anyone help ?

Cheers
Phil

Nov 19 '05 #2
Phil:
In ASP.Net it's just as simple but far more flexible. The entire point of
having a runat="server" is that it creates a rich and capable server-side
object, in this case an HtmlTableCell. Instead of messing up your html code
with <%= %> you can program against your objects to set their variables.

In other words:

<asp:TableCell id="cellContent" runat=server>...</asp:TableCell>

and then you can do, in the Page_Load event:

cellContent.ColumnSpan = NumberOfCols

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
<te*******@skunkbox.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hello

How do I perform a variable replacement in ASP.NET when I am using the
runat=server clause to generate a table - it was simple in ASP

With ASP :
----------
<HTML>
...
<BODY>
...
<TABLE...>
<TR>
<TD colspan="<%=NumberOfCols%>">...<TD>
...
<TR>
...
<TABLE>
...
</BODY>
</HTML>

With ASP.NET :
--------------
<HTML>
...
<BODY>
...
<asp:Table... runat=server>
<asp:TableRow runat=server>
<asp:TableCell ColumnSpan="<%=NumberOfCols%>"
runat=server>...</asp:TableCell>
...
</asp:TableRow>
...
</asp:Table>
...
</BODY>
</HTML>

Then the Code Behind contains
...
Protected NumberOfCols As Integer = 6
...
But executing the above <%=NumberOfCols%> is not a valid value for
Int32.

However if I print the variable by placing <%=NumberOfCols%> somewhere
within the body of the html it prints the value of it ("6") correctly.
Can anyone help ?

Cheers
Phil

Nov 19 '05 #3
Thanks Karl, it's just that I've seen
<%# DataBinder.Eval(<object>,"<fieldname>") %>
in HTML and wondered if I should be somehow using this syntax or puting
it in the code behind as you have suggested.

Many thanks for your reply
Phil

Karl Seguin wrote:
Phil:
In ASP.Net it's just as simple but far more flexible. The entire point of having a runat="server" is that it creates a rich and capable server-side object, in this case an HtmlTableCell. Instead of messing up your html code with <%= %> you can program against your objects to set their variables.
In other words:

<asp:TableCell id="cellContent" runat=server>...</asp:TableCell>

and then you can do, in the Page_Load event:

cellContent.ColumnSpan = NumberOfCols

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
<te*******@skunkbox.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hello

How do I perform a variable replacement in ASP.NET when I am using the runat=server clause to generate a table - it was simple in ASP

With ASP :
----------
<HTML>
...
<BODY>
...
<TABLE...>
<TR>
<TD colspan="<%=NumberOfCols%>">...<TD>
...
<TR>
...
<TABLE>
...
</BODY>
</HTML>

With ASP.NET :
--------------
<HTML>
...
<BODY>
...
<asp:Table... runat=server>
<asp:TableRow runat=server>
<asp:TableCell ColumnSpan="<%=NumberOfCols%>"
runat=server>...</asp:TableCell>
...
</asp:TableRow>
...
</asp:Table>
...
</BODY>
</HTML>

Then the Code Behind contains
...
Protected NumberOfCols As Integer = 6
...
But executing the above <%=NumberOfCols%> is not a valid value for
Int32.

However if I print the variable by placing <%=NumberOfCols%> somewhere within the body of the html it prints the value of it ("6") correctly. Can anyone help ?

Cheers
Phil


Nov 19 '05 #4

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

Similar topics

1
by: Gary Bagen | last post by:
Hello, I am working on a page transition scheme and was wondering what the quickest way is to find out which ASP.NET controls need to be inside a form with runat=server. I've determined that...
4
by: Matthew Louden | last post by:
It happend to me more than once. When I create web controls or move the positions in VS.NET, I encountered the following run-time errors: It doesn't matter what controls I create, the following...
3
by: Russ | last post by:
I have a usercontrol that is loaded by a webform. The usercontrol populates a datagrid which users need the capability to export data from the grid to Excel. The problem is that when I attempt to...
2
by: Roland Müller | last post by:
Hello Ng, i have a simple problem: there is a property in the code behind of a webpage public string Hyperlink { get { return "test"; } }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.