Inline output in pages

  • Thread starter Thread starter Mike Gleason jr Couturier
  • Start date 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
 
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
 
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
 
Back
Top