loads of useful information, examples and tutorials pertaining to web development utilizing asp.net, c#, vb, css, xhtml, javascript, sql, xml, ajax and everything else...

 



Advertise Here
C-Sharpener.com - Programming is Easy!  Learn Asp.Net & C# in just days, Guaranteed!

inline asp.net tags... sorting them all out (<%$, <%=, <%, <%#, etc.)

by naspinski 3/24/2008 8:56:00 AM

There are all sorts of different inline tags, and I haven't found a place that explains them all in one place, so here is the quick and dirty...

<% ... %>

The most basic inline tag, basically runs normal code: 

<% if (User.IsInRole("admin")) { %>
  You can see this
<% } else { %>
  You are no admin fool!
<%} %>

http://msdn2.microsoft.com/en-us/library/ms178135(vs.80).aspx

 

 

<%= ... %>

Used for small chunks of information, usually from objects and single pieces of information like a single string or int variable: 

The Date is now <%= DateTime.Now.ToShortDateString() %>
The value of string1 is <%= string1 %> 

http://msdn2.microsoft.com/en-us/library/6dwsdcf5(VS.71).aspx

*note: <%= is the equivalent of Response.Write() -  Courtesy of Adam from the US,thanks!

 

 

<%# .. %>

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


<asp:Repeater ID="rptMeetings" DataSourceID="meetings" runat="server">
    <ItemTemplate>
        <%# Eval("MeetingName") %>
    </ItemTemplate>
</asp:Repeater>
  

http://msdn2.microsoft.com/en-us/library/ms178366.aspx

 

 

<%$ ... %>

Used for expressions, not code; often seen with DataSources: 

<asp:SqlDataSource ID="party" runat="server" ConnectionString="<%$ ConnectionStrings:letsParty %>" SelectCommand="SELECT * FROM [table]" />

http://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx

 

 

<%@ ... %>

This is for directive syntax; basically the stuff you see at the top your your aspx pages like control registration and page declaration: 

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
<%@ Register TagPrefix="wp" Namespace="CustomWebParts" %>

http://msdn2.microsoft.com/en-us/library/xz702w3e(VS.80).aspx

 

 

<%-- ... --%>

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

    <asp:Label ID="lblAwesome" runat="server" />
    <%-- sometimes end users make me angry --%>
    <asp:LinkButton ID="lbEdit" Text="Edit" OnClick="Edit_Click" runat="server" />

http://msdn2.microsoft.com/en-us/library/4acf8afk.aspx

 

And that's that.  

kick it on DotNetKicks.com

Currently rated 4.8 by 80 people

  • Currently 4.787501/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

asp.net

Related posts

Comments

3/26/2008 12:56:24 PM

Alan
Great summary. You are missing one percent sign % in the closing tag of the comment sample ;)

Alan

3/31/2008 5:58:27 PM

Roger
Thanks for putting these all together I was wonder about this just last week.

Roger us

3/31/2008 11:48:20 PM

Adam
<%= is the equivalent of Response.Write()
just a little extra tidbit of information Smile

Adam us

4/1/2008 1:59:07 AM

Sam
I was very happy to discover the server side comments. I don't want visitors to see my snarky comments Smile

Sam us

4/1/2008 3:29:50 AM

Jay
I was just thinking of putting something like this together for my reference. Thanks for taking the time to do it!

Jay us

5/20/2008 7:57:05 AM

naspinski
Thanks for all the input!

naspinski us

7/10/2008 3:42:32 AM

pingback
Pingback from ab110.com

Always 英文技术文章参照( 五 ){ UpdateTime:2008-7-10; } My article in the cnblogs - cnblogs.com

ab110.com

7/11/2008 7:53:55 AM

Nitin
Gr8 work!!

Nitin in

9/27/2008 6:41:48 AM

Amit Saini
Thanks, it helped us a lot.

Amit Saini in

10/11/2008 1:04:36 PM

ra
Thanks a lot...

cheers
rajar india

ra in

3/11/2009 6:18:40 PM

Ven
Great Summary!Very helpful!

Ven us

7/7/2009 6:05:15 AM

Nick
Bookmarking this... thanks.

Nick us

8/20/2009 12:41:23 PM

Paul
This is great! Thanks.

Paul us


Comments are closed