What is the difference between <%: and <% = and <% # in aspx?

Possible duplicate:
What is the difference between <% #%> and <% =%>?

<% $, <% @, <% =, <% # ... what's the deal?

We apologize if this is duplicated, but it’s hard for him to convince Google.

+6
source share
2 answers

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

<%= older and only means Response.Write() .

<%# is a required expression .

+8
source

Here is a good article about them. In short:

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>-- %> 
+6
source

Source: https://habr.com/ru/post/909095/


All Articles