简体   繁体   English

在ASP.NET中调用的<%%>构造是什么?

[英]what are the <% %> constructs called in asp.net?

I am new to ASP.Net and I'm a little confused here. 我是ASP.Net的新手,在这里我有些困惑。

While learning ASP.Net through some of the articles online, I notice some of the experts using some keywords for binding data and auto incrementing a date in source code, like <%#Container.DataItemIndex + 1 %> , <%#Eval("Itemid")%> , <%#DataBinder.Eval(Container.DataItem, "itemStock")%> or <%=sectionId%> . 通过在线一些文章学习ASP.Net时,我注意到一些专家使用一些关键字来绑定数据并自动在源代码中增加日期,例如<%#Container.DataItemIndex + 1 %><%#Eval("Itemid")%><%#DataBinder.Eval(Container.DataItem, "itemStock")%><%=sectionId%>

What are theese constructs called and where can I get the list of such keywords with an explanation? theese的结构称为什么?在哪里可以得到带有解释的此类关键字列表?

these are generally known as inline tags, take note as there are quite a few different types. 这些通常称为内联标签,请注意,因为有很多不同的类型。

You can find a detailed explanation of each type here: 您可以在此处找到每种类型的详细说明:

http://naspinski.net/post/inline-aspnet-tags-sorting-them-all-out-(3c25242c-3c253d2c-3c252c-3c252c-etc).aspx http://naspinski.net/post/inline-aspnet-tags-sorting-them-all-out-(3c25242c-3c253d2c-3c252c-3c252c-etc).aspx

OR 要么

http://forums.asp.net/p/1049167/1478431.aspx#1478431 http://forums.asp.net/p/1049167/1478431.aspx#1478431

Also know as Bee-Stings: 也称为Bee-Stings:
In ASP.Net, what is the difference between <%= and <%# 在ASP.Net中,<%=和<%#之间有什么区别

  • <%@ - Page/Control/Import/Register directive <%@ -页面/控件/导入/注册指令
  • <%$ - Resource access and Expression building <%$ -资源访问和表达构建
  • <%= - Explicit output to page, equivalent to <% Response.Write( ) %> <%= -显式输出到页面,等效于<% Response.Write( ) %>
  • <%# - Data Binding. <%# - 数据绑定。 It can only used where databinding is supported, or at the page level if you call Page.DataBind() in your code-behind. 它仅在支持数据绑定的地方使用,或者如果在代码隐藏中调用Page.DataBind()在页面级别使用。
  • <% -- - Server-side comment block <% --服务器端注释块
  • <%: - Equivalent to <%= , but also HTMLEncodes() the output <%: -等效于<%= ,但也输出HTMLEncodes()

They are server side scripting delimiters . 它们是服务器端脚本定界符 There is a full explanation here already: 这里已经有完整的解释:

ASP.NET "special" tags ASP.NET“特殊”标签

The ASP.NET tag syntax is fully documented in MSDN, with code examples and links to the relevant objects and methods involved. MSDN中完整记录了ASP.NET标记语法,并提供了代码示例以及指向相关对象和方法的链接。 Fire up MSDN and search for these in the index: 启动MSDN并在索引中搜索:

<%#
<%$
<%@
<%=

@rahul, I think you seriously need to read through some books about ASP.net, to understand these basic things. @rahul,我认为您急需阅读一些有关ASP.net的书,以了解这些基本知识。

the symbol <% %> is used to put .net stuff into markup which is evaluated and replaced with the results of the expression. 符号<% %>用于将.net内容放入标记中,该标记将被评估并替换为表达式的结果。

the term <%# Container.DataItemIndex + 1 %> means that put index of the current item being bound in DataGridView etc after adding one to it. 术语<%# Container.DataItemIndex + 1 %>表示在将当前项的索引添加到DataGridView等后绑定到该项。 The container is the object used to display data like grid, data-list etc. 容器是用于显示网格,数据列表等数据的对象。

the term <%#Eval("Itemid")%> means from the object (table, custom object etc) get value of Itemid column or property. 术语<%#Eval("Itemid")%>表示从对象(表,自定义对象等)获取Itemid列或属性的值。

the term <%# DataBinder.Eval(Container.DataItem, "itemStock")%> do the same thing as above but is somewhat older. 术语<%# DataBinder.Eval(Container.DataItem, "itemStock")%>的作用与上述相同,但有些旧。

term <%=sectionId%> will ouput protected or public variable sectionId defined in code-behind file in html markup. term <%=sectionId%>将输出在html标记的代码隐藏文件中定义的受保护的或公共变量sectionId

These keywords are usualy known as 'blind method'. 这些关键字通常被称为“盲法”。 You can have more information: GoodLink 您可以拥有更多信息: GoodLink

I think they're refereed to as expressions . 我认为它们被称为表达式

They're actually very powerful, and can be customised. 它们实际上非常强大,并且可以自定义。

These keywords are known as Expressions . 这些关键字称为Expressions

They help us to set information into page when run time.For example if you define width of some panel, you can place it into web.config as application setting so that page can read its value from there,meaning value is dynamic. 它们帮助我们在运行时将信息设置到页面中。例如,如果您定义某个面板的宽度,则可以将其放置在web.config中作为应用程序设置,以便页面可以从那里读取其值,这意味着值是动态的。

Also you can access code page with declaring <%#,<%$,<%= tags so you can access page properties etc. 您也可以通过声明<%#,<%$,<%=标签来访问代码页,以便访问页面属性等。

There are lots of documentation and you can define custom expressions like Eval,Bind etc. 有很多文档,您可以定义自定义表达式,例如Eval,Bind等。

Source list: 来源清单:
Five Undiscovered Features on ASP.NET ASP.NET上的五个未发现的功能
ASP.NET Extensibility ASP.NET可扩展性
Express yourself with Custom Expression Builders 用自定义表达式构建器表达自己

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM