Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET : What does the '#' starting a <% %> mean?

I've been using the repeater control in asp.net for awhile now..and every now and then i keep forgetting to add the '#' inside the < %# DataBinder.Eval(Container.DataItem, "NAME") % >

so i was wondering what does it mean ?

like image 985
Madi D. Avatar asked Sep 30 '09 09:09

Madi D.


3 Answers

It is indicating that you are binding an expression so as you demonstrated eval or bind.

Data-Binding Syntax

Data-binding expressions are contained within <%# and %> delimiters and use the Eval and Bind functions. The Eval function is used to define one-way (read-only) binding. The Bind function is used for two-way (updatable) binding. In addition to calling Eval and Bind methods to perform data binding in a data-binding expression, you can call any publicly scoped code within the <%# and %> delimiters to execute that code and return a value during page processing.

like image 151
Johnno Nolan Avatar answered Sep 22 '22 22:09

Johnno Nolan


just to add...

you also have:

$

let's you Bind a Resource, like:

<%$ Resources:Menu, oktext %>

=

the most known binder sign, let's you do the same as the Response.Write method

<%= myVariable %> instead <% Response.Write(myvariable) %>
like image 43
balexandre Avatar answered Sep 24 '22 22:09

balexandre


New to .NET 4.0 there is

:

which is just like the <%= %> but HTML encodes your output. It is used like:

<%: Model.Name %>

And it is just like calling

<%= HttpServerUtility.HtmlEncode(Model.Name) %>  .. or ..
<% Response.Write(HttpServerUtility.HtmlEncode(Model.Name)) %>
like image 33
Nick Berardi Avatar answered Sep 22 '22 22:09

Nick Berardi