473,769 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="<%=Num berOfCols%>">.. .<TD>
....
<TR>
....
<TABLE>
....
</BODY>
</HTML>

With ASP.NET :
--------------
<HTML>
....
<BODY>
....
<asp:Table... runat=server>
<asp:TableRow runat=server>
<asp:TableCel l 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 1864
Phil,

Try to remove the quotes:

ColumnSpan=<%=N umberOfCols%>

Eliyahu

<te*******@skun kbox.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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="<%=Num berOfCols%>">.. .<TD>
...
<TR>
...
<TABLE>
...
</BODY>
</HTML>

With ASP.NET :
--------------
<HTML>
...
<BODY>
...
<asp:Table... runat=server>
<asp:TableRow runat=server>
<asp:TableCel l 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:TableCel l id="cellContent " runat=server>.. .</asp:TableCell>

and then you can do, in the Page_Load event:

cellContent.Col umnSpan = NumberOfCols

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
<te*******@skun kbox.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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="<%=Num berOfCols%>">.. .<TD>
...
<TR>
...
<TABLE>
...
</BODY>
</HTML>

With ASP.NET :
--------------
<HTML>
...
<BODY>
...
<asp:Table... runat=server>
<asp:TableRow runat=server>
<asp:TableCel l 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>,"<fie ldname>") %>
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:TableCel l id="cellContent " runat=server>.. .</asp:TableCell>

and then you can do, in the Page_Load event:

cellContent.Col umnSpan = NumberOfCols

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
<te*******@skun kbox.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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="<%=Num berOfCols%>">.. .<TD>
...
<TR>
...
<TABLE>
...
</BODY>
</HTML>

With ASP.NET :
--------------
<HTML>
...
<BODY>
...
<asp:Table... runat=server>
<asp:TableRow runat=server>
<asp:TableCel l 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
1674
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 asp:Label does not need to have the form runat=server and that asp:Textbox requires it. Thanks, Gar
4
9966
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 'checkbox' control is just an example. Control 'CheckBox1' of type 'CheckBox' must be placed inside a form tag with runat=server. Description: An unhandled exception occurred during the execution of the current web request. Please review the...
3
4180
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 export the data to excel I get the following error message: Control 'RoomReservationReport1_dgReservations__ctl2__ctl0' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server. My form tag is located in my web form...
2
3117
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
9579
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
9422
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,...
0
10208
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10038
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9857
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8867
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...
1
3952
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
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2812
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.