473,671 Members | 2,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<%= %> vs. <%# %>

Hello,

I would like to know what the difference is among the constructs
<%= %> for evaluating an expression and displaying the evaluated
result on the page and <%# %>. In particular I would like to know
why the <%# %> construct is necessary in locations where the other
<%= %> does not do. It seems to me that there is no equivalent of
the <%# %> construct in PHP, thus I thought I would post to
clarify. Is this an ASP.NET specific construct not present
in ASP? Thanks for the clarification.

Best Regards,

Neil
Nov 19 '05 #1
4 1556
Neil Zanella wrote:
I would like to know what the difference is among the constructs
<%= %> for evaluating an expression and displaying the evaluated
result on the page and <%# %>.


<%# %> is the ASP.NET data-binding expression. You can include
data-binding expressions on the value side of an attribute/value pair in
the opening tag of a server control or anywhere else in a page.

<%= %> is shorthand for Response.Write.

The Response.Write expressions are evaluated when the page is processed.
The data-binding expressions create bindings between any data source,
property, collection, expression or result returned from a method call
when the page's DataBind method is called.

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 19 '05 #2

Thank you for your reply,

However I am experiencing something strange:

The following is working fine:

<asp:TextBox Text=<%# "foo" + DataBinder.Eval
(Container.Data Item, "bar").ToString () %> runat="server"/>

but if I want to use this way to set the ID attribute it
does not seem possible, so I am not sure what to do, maybe
I should check out the CommandText property???

<asp:TextBox ID=<%# "foo" + DataBinder.Eval
(Container.Data Item, "bar").ToString () %> runat="server"/>

Parser Error Message: '<%# "foo" + DataBinder.Eval (Container.Data Item,
"bar").ToString () %>' is not a valid identifier.

Why this error? Why can't I just set the value of the
ID property in this way like I can set everything else???

Thanks,

Neil

Anders Norås wrote:
Neil Zanella wrote:
I would like to know what the difference is among the constructs
<%= %> for evaluating an expression and displaying the evaluated
result on the page and <%# %>.
<%# %> is the ASP.NET data-binding expression. You can include
data-binding expressions on the value side of an attribute/value pair

in the opening tag of a server control or anywhere else in a page.

<%= %> is shorthand for Response.Write.

The Response.Write expressions are evaluated when the page is processed. The data-binding expressions create bindings between any data source, property, collection, expression or result returned from a method call when the page's DataBind method is called.

Anders Norås
http://dotnetjunkies.com/weblog/anoras/


Nov 19 '05 #3
nz******@cs.mun .ca wrote:
Thank you for your reply,

However I am experiencing something strange:

The following is working fine:

<asp:TextBox Text=<%# "foo" + DataBinder.Eval
(Container.Data Item, "bar").ToString () %> runat="server"/>

but if I want to use this way to set the ID attribute it
does not seem possible, so I am not sure what to do, maybe
I should check out the CommandText property???

<asp:TextBox ID=<%# "foo" + DataBinder.Eval
(Container.Data Item, "bar").ToString () %> runat="server"/>

Parser Error Message: '<%# "foo" + DataBinder.Eval (Container.Data Item,
"bar").ToString () %>' is not a valid identifier.

Why this error? Why can't I just set the value of the
ID property in this way like I can set everything else???


I guess the ID is necessary for viewstate purposes, and shouldn't be
tempered with at runtime.

If you need some tag to identify your textbox, use the CommandArgument
property.

--

Riki
Nov 19 '05 #4
nz******@cs.mun .ca wrote:
Why this error? Why can't I just set the value of the
ID property in this way like I can set everything else???

No. The identifier is used to uniquely identify the control within the
page. Therefore, the id must be unique when the page is parsed. Since
the page is parsed before data binding takes place, it cannot be data bound.

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 19 '05 #5

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
3210
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
11038
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
8483
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
8402
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
8927
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...
1
8605
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,...
1
6237
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
4227
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
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1816
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.