aspx variable replacement - runat=server

T

testemail

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
 
K

Karl Seguin

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
 
T

testemail

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top