226

I've programmed in both classic ASP and ASP.NET, and I see different tags inside of the markup for server side code.

I've recently come across a good blog on MSDN that goes over the difference between:

  • <%= (percentage together with equals sign) and
  • <%# (percent sign and hash/pound/octothorpe)

(<%# is evaluated only at databind, and <%= is evaluated at render), but I also see:

  • <%$ (percent and dollar sign) and
  • <%@ (percent sign and at symbol).

I believe <%@ loads things like assemblies and perhaps <%$ loads things from config files? I'm not too sure.

I was just wondering if anyone could clarify all of this for me and possibly explain why it's important to create so many different tags that seemingly have a similar purpose?

6
  • 77
    I'm glad you ask, because it's very hard to google ;) Jun 5, 2009 at 18:18
  • 10
    Impossible to Google!
    – jdbosley
    Jul 25, 2014 at 16:18
  • 1
    <%# is often used with eval, but it doesn't have to: you can use it to run any server side code, provided that you run Page.DataBind() on the containing page or its master page. It seems that this is your only option in case you want to "inject" server side code into attributes of server side controls such as <asp:TextBox, <asp:LinkButton or even a <input runat="server">. Apr 30, 2015 at 7:20
  • 1
    @jdbosley I googled "<%=" "<%:""<%@" "<%#" and it sent me here.
    – Rudey
    Apr 4, 2017 at 8:57
  • 2
    @RuudLenders, lucky for you and good job Google. In 2014 searching those tags did not return good quality results.
    – jdbosley
    Jun 6, 2017 at 20:57

2 Answers 2

319
9
  • 8
    Is there a name for all these? What are these called as a group?
    – Vippy
    Feb 26, 2015 at 18:25
  • 11
    @Vippy They are called bee stings.
    – Ian Boyd
    Jun 30, 2015 at 18:46
  • 1
    @IanBoyd Where does the term bee stings come from?
    – user692942
    Mar 15, 2016 at 13:27
  • 2
    @Lankymart Earliest usage i can find is September 2008
    – Ian Boyd
    Mar 15, 2016 at 19:39
  • 1
    Maybe my testing method sucks, but I can't see a difference between <%# %> and <%#: %>. Both of them HTML encode the value. May 23, 2016 at 3:39
6

You've covered 2 of them (<%# is evaluated only at databind, and <%= is evaluated at render), and the answer for "<%@" is that it's compiler directives (ie., stuff like what you'd put on a compiler's command line).

I don't know about "<%$".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.