English 中文(简体)
.NET “代码核心区块”?
原标题:.NET "code nugget blocks"?

页: 1 NET 我们有......

<%=

<%: (new to .NET 4 - syntactic sugar for HTML encoding)

<%#

<%@

What exactly are these?

And are there more? Is there an exhaustive list of these and what they are anywhere? It s hard to know what to even search for - I didn t even hear of the term "code nugget blocks" til tonight when I discovered what <%: was.

问题回答

这些术语通常称为code nuggets,但微软文件中并不存在这一术语。 微软电话inline expression as in Introduction to ASP。 NET inline expression in the .NET Framework. 他们提供协会。 NET 关于如何在这些符号内处理声明的框架指示(<%>); 在我知道自己的名字之前,如果是的话,在社区内就更不用说。 不能确定详尽无遗的清单,但比你具体指明的多。 以下是其他代码清单及其用途和样本。

www.un.org/Depts/DGACM/index_french.htm


<% --Standard code nugget--Indicates that the following statements are C# statements. Will have to follow C# syntax rules. eg.

<% string[] cities = { ""London"", ""New York"", ""Paris"" };
string myCity = cities[new Random().Next(cities.Length)];
Response.Write(myCity);%>

<%= --Content code nugget--Similar to standard cn, difference being the returned result is directly inserted into response to the browser without having to use Response.Write. eg.

<%=textBox.Text%> 

(NOT RecommendationsED, includes risk of html injection attacks. 如果对文本箱的投入如“<但顿型 = 提交和gt; Submit</button >,则将添加一个顿页。 当然,这一点是肯定的,但希望这一点是明确的。


<%: --Encoded code nugget --Similar to <%=, but the response is HTML encoded. eg. Name is <%:textBox.Text%> (whatever the input is on the text box, it is displayed. If the input is something like "< button type = submit > Submit</button >", output would be "Name is <button type = submit> Submit</button>".


<编码> <%# - 具有法律约束力的法规 - 表示采用数据约束代码Nugget,用以指当前数据标。 只有采用数据组合控制,如重复控制等。

<编码> <%#:- 编码数据具有约束性-表示在编码数据限值时采用编码数据约束代码表示。 例如。

<asp:Repeater ItemType = ""System.String"" SelectMethod = ""GetCities"" runat = ""server">
<ItemTemplate>
<li > <%# Item % > </li>
</ItemTemplate>
</asp:Repeater> 

(如果编码(<%#:)使用,则显示字面没有解释,建议”。)


<代码><%——Property Code nugget-Used to refer to composition Value, such as those specified in Web.config.

<asp:Literal Text = " < %$ AppSettings: cityMessage % > " runat = "server" /> 

(从公交档案中收回城市职业钥匙的价值)


<编码> <%@ - 工资指令-这一指示用于根据指令类型对网上表格(或控制或主页)进行配置。 例如。

<%@ Page.. <%@ Master

上述所有资料和实例都来自Adam Freemans Pro ASP .NET 4.5书,第12章。 Excellent book imo.

这些指示为<代码><%@。 详细清单和文件见MSDN

When used, directives can be located anywhere in an .aspx or .ascx file, though standard practice is to include them at the beginning of the file. Each directive can contain one or more attributes (paired with values) that are specific to that directive.

The <% are script/2005/4. http://msdn.microsoft.com/en-us/library/ms178135.aspx” rel=“nofollow” 页: 1

An embedded code block is server code that executes during the page s render phase. The code in the block can execute programming statements and call functions in the current page class.

<代码><%#栏通常用于约束控制。 See this short article for more info.

很难明确和确定名称,因为微软往往不明确和明确。 例如,我不知道<代码>和>名称是什么;%:...... %>。

It is also difficult to be certain of what the current documentation is and Microsoft is working on solving that problem.

The following table cross-references what is in Introduction to ASP.NET inline expressions in the .NET Framework with what is in ASP.NET Page Syntax.

    Syntax      | Support Article           | Docs
    <% ... %>     | Embedded Code Block       | inline code (see Code Render Blocks)
    <%= ... %>    | Inline Expression Block   | inline expression (see Code Render Blocks)
    <%@ ... %>    | Text Template Directive   | Text Template Directive
    <%# ... %>    | Data-Binding Expression   | Data-Binding Expression
    <%$ ... %>    | Expression Builder        | ???
    <%-- ... %>   | Server-Side Comments      | Server-Side Comments
    <%: ... %>    | N/A                       | N/A

<% ... %>: Embedded Code Block

受到遗弃的《法典》区提供与传统协会的后向兼容性,也由公共卫生和社会福利部和菲律宾统计局使用。 由于它们包含在超文本中,它们往往难以阅读和维护超文本。

<%= ... %>: Inline Expression Block

An Inline Expression Block is executed as if it is a parameter of a Response.Write(…) statement.

<%: ... %>: ???

• 服务器; HtmlEncode。

<%@ ... %>: Text Template Directive

文本模板指令具体规定了网页和用户控制汇编者处理伙伴关系时所使用的环境。 NET Web Form (.aspx) pages anduser Control (.ascx) file.

<%# ... %>: Data-Binding Expression

数据制表述将服务器控制财产与数据来源挂钩。

<%$ ... %>: Expression Builder

表达式建筑商将控制财产的价值确定在申请组合或资源档案中的价值。 1. 言论自由包括:

Expression Prefix: Expression Value

如果言辞是表达方式,例如网上的节点,书面文档和表达价值是节点的关键名称。 结果是该钥匙的具体价值。

<%-- ... %>: Server-Side Comments Block

服务器评论栏允许将评论放到任何地方,但密码区除外。

Miscellaneous Syntax

The following are also in the Microsoft Docs documentation page, in case that helps.

    Syntax                                      | Docs
    <tagprefix:tagname runat="server"/>       | Custom Server Control
    <object id="id" runat="server"/>          | Server-Side Object Tag
    <!-- #include file|virtual="filename" --> | Server-Side Include Directive

作者Adam Freeman在引入视觉C# 2010时写道:

The official term for the <% and %> tags is server-side scripting delimiters although they are more commonly referred to as code nuggets.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签