Search code examples
asp.netcoding-styleinline-scripting

Inline scripting in ASP.NET


I want to learn advanced and basic things about ASP.NET inline scripting like

<img src="<%= Page.ResolveUrl("~")%>Images/Logo.gif"/>

or

<asp:Label ID="lblDesc" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Description")%>'></asp:Label>

And so on...

And, what's the difference between <% %> and <%# %> and such stuff?

Where can I find from basic to advanced implementation of those usages?


Solution

  • Check out this article for the specifics of the different inline tag options.

    From the article:

    <% ... %> -- The most basic inline tag, basically runs normal code:

    <%= ... %> -- Used for small chunks of information, usually from objects and single pieces of information like a single string or int variable:

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

    <%$ ... %> -- Used for expressions, not code; often seen with DataSources:

    <%@ ... %> -- This is for directive syntax; basically the stuff you see at the top your your aspx pages like control registration and page declaration:

    <%-- ... %> -- This is a server side comment, stuff you don't want anyone without code access to see: