Inline output in pages

  • Thread starter Mike Gleason jr Couturier
  • Start date
M

Mike Gleason jr Couturier

Hi,

In an .aspx file, is there any clear/concise documentation about the
difference between the following:


<%$ [...]
<%= [...]
<%# [...]

and where we can use them?

How are those called?

Thanks!

Mike
 
G

George Ter-Saakov

The
<%= is a substitute for Response.Write
So <%= a%> is exactly the same as <%Response.Write(a)%> and executes only
during Render even, and is used to write something to browser
-----------------------------------------------
<%# is called data binding. <%# Methods%> will be executed during so called
"binding". It's used to assign some value to property

Example:
<asp:label text='<%# MyValue %>' runat="server"/>
You can not write here <%= instead of <%# simply because it will not make
sense. You want to assign to text property of the label the value of
MyValue.

PS. to kick of execution of data binding you need to call Page.DataBind();

The most common use for <%# is in DataGrid and such. When you write
<asp:TemplateColumn HeaderText="FAQ Information">
<ItemTemplate>
<b><%# DataBinder.Eval(Container.DataItem, "ColumnName") %></b>
</ItemTemplate>
</asp:TemplateColumn>this code is actually assignment to the ItemTemplate
property. so you can not use <%= instead.PS: You do not need to call
Page.DataBind() in this case but you do need to call MyGrid.DataBind() for
assignment to actually happen. (Of course if you do not have Page scope
biding
elements) -----------------------------------------------------------------
The
<%$ is the synonymous for pulling value from the resource (or web.config ).
My understanding that it happens during compile time. And not runtime.
So you can not write someting like
"<%$ ConnectionStrings:GetMyConnection()%>"
Becuase GetMyConnection is evaluated during parse time and your code is not
running at that time.

George
 
M

Mike Gleason jr Couturier

George Ter-Saakov said:
The
<%= is a substitute for Response.Write
So <%= a%> is exactly the same as <%Response.Write(a)%> and executes only
during Render even, and is used to write something to browser
-----------------------------------------------
<%# is called data binding. <%# Methods%> will be executed during so
called "binding". It's used to assign some value to property

Example:
[...]

Thank you very much, it is now 100% clear in my head, thanks again!

Mike
 

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,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top