473,666 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why use <%= %> ?

Hello,

Newbie alert, so please be patient <g>

I ASP Classic, we were used to using tricks like ...

<%=strName%>

to insert dynamic content into an HTML block. In ASP.NET, you have
various controls like the label that seem to do the same thing, but with
much more power and flexibility. If so, is there any reason to use <%=
%> at all?

I only ask as I am reading ASP.NET Unleashed, and he shows an example of
using this. I couldn't see why he didn't just use a control. Granted his
example was something like ...

<body bgcolor="<%=str Colour%>">

where he was including an attribute for a tag, rather than a whole tag,
but he already mentioned a generic control that just produced the basic
text rather than a tag, so why not use that?

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #1
12 1180
Alan:
You are right, there's almost never a good reason to prefer <%= %> over
using controls. True <%= %> might be nanoseconds faster, but you pay the
price (about 10x over) with maintenance and bugs. Hopefully the book was
just showing that you COULD do it. There might be very odd occasions were
you want to. Someone recently asked how to create a <base> tag...at ifrst I
thought just use <base id="x" runat="server" /> and declare it as an
HtmlGenericCont rol...but it turns out <base> CAN'T have a closing tag, and
all server/html controls render a closing tag. I provided the guy with a
server control which overwrote the closing tag behaviour, but using <%= %>
might have been an easier solution for him to use...There have been other,
although I can probably count them on a single hand, occasions...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Alan Silver" <al*********@no spam.thanx> wrote in message
news:gO******** ******@nospamth ankyou.spam...
Hello,

Newbie alert, so please be patient <g>

I ASP Classic, we were used to using tricks like ...

<%=strName%>

to insert dynamic content into an HTML block. In ASP.NET, you have
various controls like the label that seem to do the same thing, but with
much more power and flexibility. If so, is there any reason to use <%=
%> at all?

I only ask as I am reading ASP.NET Unleashed, and he shows an example of
using this. I couldn't see why he didn't just use a control. Granted his
example was something like ...

<body bgcolor="<%=str Colour%>">

where he was including an attribute for a tag, rather than a whole tag,
but he already mentioned a generic control that just produced the basic
text rather than a tag, so why not use that?

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 19 '05 #2
Good example. There is nothing in asp.net representing <body> tag, so use of
<%... is appropriate. You can replace <body> with a generic control (then
you will end up with two <body>). Also you might prefer keeping your old asp
style.

Eliyahu

"Alan Silver" <al*********@no spam.thanx> wrote in message
news:gO******** ******@nospamth ankyou.spam...
Hello,

Newbie alert, so please be patient <g>

I ASP Classic, we were used to using tricks like ...

<%=strName%>

to insert dynamic content into an HTML block. In ASP.NET, you have
various controls like the label that seem to do the same thing, but with
much more power and flexibility. If so, is there any reason to use <%=
%> at all?

I only ask as I am reading ASP.NET Unleashed, and he shows an example of
using this. I couldn't see why he didn't just use a control. Granted his
example was something like ...

<body bgcolor="<%=str Colour%>">

where he was including an attribute for a tag, rather than a whole tag,
but he already mentioned a generic control that just produced the basic
text rather than a tag, so why not use that?

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 19 '05 #3
>Alan:
You are right, there's almost never a good reason to prefer <%= %> over
using controls. True <%= %> might be nanoseconds faster, but you pay the
price (about 10x over) with maintenance and bugs. Hopefully the book was
just showing that you COULD do it.
OK, I guessed it wasn't necessary (usually), but it's nice tohave it
confirmed.
There might be very odd occasions were
you want to. Someone recently asked how to create a <base> tag...at ifrst I
thought just use <base id="x" runat="server" /> and declare it as an
HtmlGenericCon trol...but it turns out <base> CAN'T have a closing tag, and
all server/html controls render a closing tag. I provided the guy with a
server control which overwrote the closing tag behaviour, but using <%= %>
might have been an easier solution for him to use...There have been other,
although I can probably count them on a single hand, occasions...


OK, forgive the ignorance as I'm *really* new at this, but I think I
read that one of the generic controls just produces pretty much what you
put in, which could be plain text. If I'm right, then can't you use that
instead? Or can't you use a control inside a tag? Just occurred to me as
I'm typing that this might not work.

Thanks

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #4
>Good example. There is nothing in asp.net representing <body> tag, so use of
<%... is appropriate. You can replace <body> with a generic control (then
you will end up with two <body>). Also you might prefer keeping your old asp
style.
I'm trying hard to learn ASP.NET as it is meant to be, not as a step
from ASP Classic ;-) I'm trying to get it right from the start, not keep
old ideas hanging over. Not easy ;-)

Thanks
Eliyahu

"Alan Silver" <al*********@no spam.thanx> wrote in message
news:gO******* *******@nospamt hankyou.spam...
Hello,

Newbie alert, so please be patient <g>

I ASP Classic, we were used to using tricks like ...

<%=strName%>

to insert dynamic content into an HTML block. In ASP.NET, you have
various controls like the label that seem to do the same thing, but with
much more power and flexibility. If so, is there any reason to use <%=
%> at all?

I only ask as I am reading ASP.NET Unleashed, and he shows an example of
using this. I couldn't see why he didn't just use a control. Granted his
example was something like ...

<body bgcolor="<%=str Colour%>">

where he was including an attribute for a tag, rather than a whole tag,
but he already mentioned a generic control that just produced the basic
text rather than a tag, so why not use that?

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)



--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #5
What, in the body tag, are you trying to set programmaticall y? There are
almost always more than 1 way to do things ;)

Mythran
Nov 19 '05 #6
There are controls which let you render text or even html inside a tag, but
I don't think there are any that let you define the attributes via
strings...even if they did, it would be the same as using <%= %> as you
wouldn't be able to program against it.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Alan Silver" <al*********@no spam.thanx> wrote in message
news:Vr******** ******@nospamth ankyou.spam...
Alan:
You are right, there's almost never a good reason to prefer <%= %> over
using controls. True <%= %> might be nanoseconds faster, but you pay the
price (about 10x over) with maintenance and bugs. Hopefully the book was
just showing that you COULD do it.


OK, I guessed it wasn't necessary (usually), but it's nice tohave it
confirmed.
There might be very odd occasions were
you want to. Someone recently asked how to create a <base> tag...at ifrst Ithought just use <base id="x" runat="server" /> and declare it as an
HtmlGenericCon trol...but it turns out <base> CAN'T have a closing tag, andall server/html controls render a closing tag. I provided the guy with a
server control which overwrote the closing tag behaviour, but using <%= %>might have been an easier solution for him to use...There have been other,although I can probably count them on a single hand, occasions...


OK, forgive the ignorance as I'm *really* new at this, but I think I
read that one of the generic controls just produces pretty much what you
put in, which could be plain text. If I'm right, then can't you use that
instead? Or can't you use a control inside a tag? Just occurred to me as
I'm typing that this might not work.

Thanks

--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 19 '05 #7
>What, in the body tag, are you trying to set programmaticall y? There are
almost always more than 1 way to do things ;)


The example I saw in the book was using <%=%> to set the bgcolor
attribute of the body tag. It was a simple example where you pick a
colour from a set of radio buttons, and the page is set to use that
colour when you post back.

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #8
>There are controls which let you render text or even html inside a tag, but
I don't think there are any that let you define the attributes via
strings...ev en if they did, it would be the same as using <%= %> as you
wouldn't be able to program against it.


Why not? If you had a control that produced an attribute, you could
program against it. I can see that it would be the same as using <%=%>,
except that the code would be written in a more ASP.NET way, using
controls and setting them in the code block, rather than inserting code
in the HTML section, which is more of a Classic ASP approach.

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #9
Well, if you did:

myControl.Attri buteString = "href='somevalu e.html' target='_blank' "

you can't program against the href and target, in other words you couldn't
go

myControl.href = 'xxx' or
myControl.targe t = 'yyy'

they wouldn't be properties..jus t a string to render out..thankfully nothing
like that exists. You can always do control.Attribu tes.Add("href",
"blah.html" ) but that didn't solve the original problem of no closing
tag...

the code might not be in the HTML, but really you haven't solved the
uglyness, just moved it.

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Alan Silver" <al*********@no spam.thanx> wrote in message
news:Bs******** ******@nospamth ankyou.spam...
There are controls which let you render text or even html inside a tag, butI don't think there are any that let you define the attributes via
strings...ev en if they did, it would be the same as using <%= %> as you
wouldn't be able to program against it.


Why not? If you had a control that produced an attribute, you could
program against it. I can see that it would be the same as using <%=%>,
except that the code would be written in a more ASP.NET way, using
controls and setting them in the code block, rather than inserting code
in the HTML section, which is more of a Classic ASP approach.

--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 19 '05 #10

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

Similar topics

9
2955
by: Francesco Moi | last post by:
Hello. I'm trying to build a RSS feed for my website. It starts: ----------------//--------------------- <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd"> <rss version="0.91"> ----------------//----------------------
1
6820
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
2
3209
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are writing one object in C# which will take the entire table tag contents and renders. Ie., we need to pass "<table>………… <thead>……</thead>. <tr>.<td> <td>..<tr>.<td> <td> </table>" content to
2
10555
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script type="text/javascript"> <!]> </script> <script type="text/javascript"
0
2059
by: Arne Schirmacher | last post by:
I want to display a MySQL database field that can contain HTML markup. If I use <esql:get-string> then I get all of the database field, but all tags are escaped which is not what I want. If I use <esql:get-xml> the tags are not escaped, but only the first part of the database field is displayed. The content of the database field is: "<h1>Title</h1><h2>Subtitle</h2>"
4
62096
by: higabe | last post by:
Three questions 1) I have a string function that works perfectly but according to W3C.org web site is syntactically flawed because it contains the characters </ in sequence. So how am I supposed to write this function? String.replace(/</g,'&lt;');
2
22938
by: Francesco Moi | last post by:
Hello. I designed a form to edit some DataBase's fields. But some of these fields contain '&lt;' and '&gt;' characters. And these characters are '<' and '>' in HTML. So if want to edit these fields, the form converts them into '<' and '>'. And I want to mantain '&lt;' and '&gt;' Mi piece of code:
34
11035
by: Mark Moore | last post by:
It looks like there's a pretty serious CSS bug in IE6 (v6.0.2800.1106). The HTML below is validated STRICT HTML 4.01 and renders as I would expect in Opera, FrontPage, and Netscape. For some reason, there's an annoying vertical gap between adjacent rules that doesn't go away. This looks like IE6 is incorrectly setting the margin to some arbitrary value. Does anyone know if this is a known bug at MS? If you know of one, post the...
11
13687
by: Les Paul | last post by:
I'm trying to design an HTML page that can edit itself. In essence, it's just like a Wiki page, but my own very simple version. It's a page full of plain old HTML content, and then at the bottom, there's an "Edit" link. So the page itself looks something like this: <HTML><HEAD><TITLE>blah</TITLE></HEAD><BODY> <!-- TEXT STARTS HERE --> <H1>Hello World!</H1> <P>More stuff here...</P>
6
24307
by: tentstitcher | last post by:
Hi all: I have a source xml document with an element of type string. This element contains something like the following: <stringData> &lt;Header&gt; &lt;Body&gt; </stringData> I would like to apply an XSLT and replace all occurances of &lt; with < and &gt; with >.
0
8449
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
8876
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
8784
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...
1
8556
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
7387
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
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5666
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
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4371
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.