What's the difference between <% %> and <%# %> ???

Hello,

Could some one explain me what's the difference between:

<% ... some asp.net code %>

and

<%# ... some asp.net code %>

What's the # for?

Thanks in advance.
richardhaegerAsked:
Who is Participating?
 
GreymanMSCConnect With a Mentor Commented:
The first simply executes inline ASP code at that point in the HTML rendering.  It is generally placed in innerHTML, as if it were an HTML tag in its own right.
The second performs databinding on Eval() or Bind() calls.  It is generally placed in the value of an attribute  of an ASP control, that itself is inside a Databound Container Control, and the # symbol escentially means: bind the result of this code to the value of the control attribute containing it.

<% If Me.chkSayHellow.Checked Then Response.Write('Hello World') %>
 
<asp:Label ID=lblWhatAmI runat=server Text='<%# Eval('WhatAmI') %> />

Open in new window

0
All Courses

From novice to tech pro — start learning today.