Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between <%: and <%= and <%# in aspx? [duplicate]

Tags:

asp.net

Possible Duplicate:
What's the difference between <%# %> and <%= %>?
<%$, <%@, <%=, <%# … what's the deal?

I apologise if this is duplicated, but it's infuriatingly difficult to google for.

like image 993
NibblyPig Avatar asked Feb 22 '12 16:02

NibblyPig


2 Answers

<%: is new to .NET 4.0 - it is equivalent to HttpUtility.HtmlEncode(Response.Write()).

<%= is older and stands for Response.Write() only.

<%# is a binding expression.

like image 200
Oded Avatar answered Oct 13 '22 08:10

Oded


Here's a good article on them. In summary:

Page Directive

<%@ Page Language="C#"  %>

Rendering Code

<% Response.Write("Hello World!");  %>

<%= SayHello("Ahmed") %>

<%: DateTime.Now.ToString()  %>

Expression Syntax

<%$ ConnectionStrings:ConnStrFromWebConfig  %>

<%$ AppSettings:ValueFromWebConfig  %>

<%$ Resources:Resource, Arabic  %>

<%$ RouteValue:year  %>

<%$ YourExpressionPrefix : Any   %>

Data Binding Syntax

<%# Eval("Name")  %>

<%# Bind("Name")  %>

<%# XPath ("Name")  %>

Comment Server

<%-- <asp:Label runat="server" Text="Label"></asp:Label>-- %>
like image 25
geekchic Avatar answered Oct 13 '22 09:10

geekchic