tags:

views:

32

answers:

2

I was reading an .aspx file to see how it works. In a few places I saw things like:

<%# GetName( Container ) %>

I was wondering what this does. Thanks

+2  A: 

It is a data binding expression.

Data-binding expressions create bindings between a server control property and a data source

When you have called DataBind, the binding expressions get evaluated.

There are other <%%> types of expressions - see the links on the asp.net page syntax index page.

Oded
in this case, what does GetName and Container do? Are they defined elsewhere?
jamesatha
Yes. `GetName` looks like a function defined in the code-behind, and `Container` refers to the data container that is bound.
Oded
@oded - Is the use of the hash (#) new to the .NET Framework 4? Also, you said: "When you have called DataBind, the binding expressions get evaluated." I thought that <% ... %> and <%= ... %> and <%# ... %> expressions got evaluated regardless of if DataBind is called?
Emilio
@Emilio - it has been there at least since .NET 2.0, and probably since before. `<%%>` and `<%=%>` are called "code render blocks", they are not the same as binding expressions (`<%#%>`). `<%:%>` is a code render block that _was_ introduced in .NET 4.
Oded
A: 

<%# Used for Binding Expressions; such as Eval and Bind, most often found in data controls like GridView, Repeater, etc.:

From here http://naspinski.net/post/inline-aspnet-tags-sorting-them-all-out-(3c25242c-3c253d2c-3c252c-3c252c-etc).aspx

I've not seen it much. The must common is just <% or for outputing html use <%:

Hope this helps.

Ash Burlaczenko