Monday, May 19, 2014

Not your father's embedded code blocks

ASPX files (ASP.NET) now use many more prefixes for inline (aka embedded) code blocks.

<% ... %>
<%= ... %>
<%@ ... %>
<%# ... %>
<%$ ... %>
<%-- ... %>

And naturally they're difficult strings to Google for.
You should already know the equal sign is a shortcut for response.write, and the @ (at-sign) is for DIRECTIVES.
The complete list of directives, of which you should be familiar with the Page, is:
The ASP.NET page framework supports the following directives:
@ Page Defines page-specific attributes that are used by the ASP.NET page parser and compiler. Can be included only in .aspx files.
*This directive name can be used only in ASP.NET Web Form pages.

@ Control Defines control-specific attributes that are used by the ASP.NET page parser and compiler. Can be included only in .ascx files (user controls).
*This directive name can be used only in User Control files.

@ Import Explicitly imports a namespace into a page or into a user control.

@ Implements Declaratively indicates that a page or a user control implements a specified .NET Framework interface.

@ Register Associates aliases with namespaces and with class names. This enables user controls and custom server controls to be rendered when they are included in a requested page or user control.

@ Assembly Links an assembly to the current page during compilation. It makes all the assembly's classes and interfaces available for use on the page.

@ Master Identifies an ASP.NET master page.

@ WebHandler Identifies an ASP.NET IHttpHandler page.

@ PreviousPageType Provides a way to obtain strong typing against the previous page as accessed through the PreviousPage property.

@ MasterType Assigns a class name to the Master property of an ASP.NET page. Provides a way to create a strongly typed reference to the ASP.NET master page.

@ OutputCache Declaratively controls the output caching policies of a page or of a user control.

@ Reference Declaratively links a page or user control to the current page or user control.

The hash (number sign), # , is for data-binding expressions.

The dollar sign , $ , is for CONFIGURATION FILE, settings access, though Microsoft names this 'expression builder' usage.

No comments: