3

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?

Esteban Küber
  • 36,388
  • 15
  • 79
  • 97
  • 2
    Dupe: http://stackoverflow.com/questions/1221715/whats-the-actual-name-of-tags/1222344#1222344 – Wolfwyrd Oct 06 '09 at 13:06
  • Whatever they're called, I use them so infrequently that when I need one I can never remember which one I need and I get mad. I guess it's time to print out a cheat sheet. – Greg Oct 06 '09 at 13:08
  • A pain in the ass, most of the time. :) – rick schott Oct 06 '09 at 13:13

8 Answers8

3

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

Dalbir Singh
  • 2,629
  • 3
  • 26
  • 29
  • Server Side Scripting Delimiters (from MSDN: http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/iisbook/c06%5Fasp%5Fserver-side%5Fscripting.mspx?mfr=true) – Wolfwyrd Oct 06 '09 at 13:09
3

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
Community
  • 1
  • 1
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
2

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

ASP.NET "special" tags

Community
  • 1
  • 1
Wolfwyrd
  • 15,716
  • 5
  • 47
  • 67
0

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:

<%#
<%$
<%@
<%=
Christian Hayter
  • 30,581
  • 6
  • 72
  • 99
0

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

TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188
  • Yeah, its probably worth getting a book on Beginning ASP.NET to get to grips with the technology. I generally find web tutorials are OK for specific things, but don't give you the full scope of the technology like a book does. – Dalbir Singh Oct 06 '09 at 13:10
0

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

AndreyAkinshin
  • 18,603
  • 29
  • 96
  • 155
0

I think they're refereed to as expressions.

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

Kieron
  • 26,748
  • 16
  • 78
  • 122
0

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

Myra
  • 3,646
  • 3
  • 38
  • 47