简体   繁体   中英

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

I am new to ASP.Net and I'm a little confused here.

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

What are theese constructs called and where can I get the list of such keywords with an explanation?

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

OR

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

Also know as Bee-Stings:
In ASP.Net, what is the difference between <%= and <%#

  • <%@ - Page/Control/Import/Register directive
  • <%$ - Resource access and Expression building
  • <%= - Explicit output to page, equivalent to <% 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.
  • <% -- - Server-side comment block
  • <%: - Equivalent to <%= , but also HTMLEncodes() the output

They are server side scripting delimiters . There is a full explanation here already:

ASP.NET "special" tags

The ASP.NET tag syntax is fully documented in MSDN, with code examples and links to the relevant objects and methods involved. Fire up MSDN and search for these in the index:

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

@rahul, I think you seriously need to read through some books about ASP.net, to understand these basic things.

the symbol <% %> is used to put .net stuff into markup which is evaluated and replaced with the results of the expression.

the term <%# Container.DataItemIndex + 1 %> means that put index of the current item being bound in DataGridView etc after adding one to it. 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.

the term <%# DataBinder.Eval(Container.DataItem, "itemStock")%> do the same thing as above but is somewhat older.

term <%=sectionId%> will ouput protected or public variable sectionId defined in code-behind file in html markup.

These keywords are usualy known as 'blind method'. You can have more information: GoodLink

I think they're refereed to as expressions .

They're actually very powerful, and can be customised.

These keywords are known as 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.

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.

Source list:
Five Undiscovered Features on ASP.NET
ASP.NET Extensibility
Express yourself with Custom Expression Builders

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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