1

I have the following piece of code:

<div id='mymodal' class="modal hide fade <%# CssClass %>">
    <div class="modal-header">
        <asp:HyperLink ID="closePopup" NavigateUrl='<%# CloseLink %>' CssClass="close" runat="server" >&times;</asp:HyperLink>
        <h3>
            <asp:Literal ID="header" Text='<%# Header %>' runat="server" />
        </h3>
    </div>
    <div class="modal-body">
        <asp:Literal ID="body" Text='<%# Body %>'  runat="server" />
    </div>
</div>

The first CssClass binding works either with <%# or <%=, while the other ones only work with <%# + codebehind DataBind() (if I use <%=, then the two Literals display literally the "<%= Body %>" text).

What is the use of both approaches? Why does it work this way? Which are the advantages of one over the other?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
David Jiménez Martínez
  • 3,053
  • 5
  • 23
  • 43

3 Answers3

2

<%= is mean for Response.Write()

<%# is used to data binding

referred From

Can you tell the differences between <%= %>, <%# %> and <%$ %> ASP.NET expressions?

I hops this links helps to you lot...

Community
  • 1
  • 1
1

As suggested by Dan Crevier

http://blogs.msdn.com/b/dancre/archive/2007/02/13/the-difference-between-lt-and-lt-in-asp-net.aspx

The literal expression made it down to the browser and it's just invalid HTML. What you can see as a result is:

•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.

So in short <%= %> is equivalent of Response.Write(); and

<%# %>  is used for data-binding expressions.
Neel
  • 11,625
  • 3
  • 43
  • 61
0

<% %> is for inclusion of server-side code to the Render() method

<%# %> is used for data-binding expressions

To know more delimiters:

ASP.NET "special" tags

Community
  • 1
  • 1
Kumar Manish
  • 3,746
  • 3
  • 37
  • 42