ASP inline tags explained

There are a couple of inline tags and here they are quickly explained:
<% … %>

This is the basic asp tag, which is used to execute normal code in the aspx page:

<% 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

<%= … %>

This tag is used to get the value of a variable or display a property of a control (i.e. TextBox1.Text)

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 equivalent to Response.Write()

<%# .. %>

This is one is used for so called binding expressions (Bind and Eval). Like in a GridView template column, when you want to set the text property of a label to the value of the column in the datasource:

It’s used in GridView, Repeater, DetailsView и т.н.

<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 one is used for descriptions or directives, or simply said the things you see on top of each of your aspx pages.

<%@ 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.

<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

Advertisement
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s