Wednesday 22 December 2010

The difference between '<%#' and '<%=' in ASP.NET

I have been trying to work out the difference between "<%#" and "<%=" when writing markup for an ASP.Net site. Sometimes the = sign worked, and sometimes the # sign works but switching them usually sorted out the problem but I was never really sure why.

I found a post on Dan Crevier's Blog that explained the difference very well.

To sum it up it works as follows:
  • The "<%=" expressions are evaluated at render time
  • The "<%#" expressions are evaluated at DataBind() time and are not evaluated at all if DataBind() is not called.
  • "<%#" expressions can be used as properties in server-side controls. "<%"= expressions cannot.

No comments:

Post a Comment