Article ID: 976112 - View products that this article applies to.
This article contains an introduction to the following ASP.NET inline expressions:
<% ... %> embedded code blocksThe embedded code block is used to preserve backward compatibility with classical ASP. The code in the block can execute programming statements and call functions in the current page class during the page-rendering phase.
The following example demonstrates an ASP.NET page that has sample Microsoft Visual Basic .NET code in an embedded code block to display the results of a loop:
Because an embedded code block is always mixed with the HTML source, it is difficult for developers to read and maintain them.
For more information about embedded code blocks in ASP.NET Web pages, visit the following Microsoft Developer Network (MSDN) Web site:
<%= ... %> displaying expressionThe <%= ... %>displaying expression is an equivalent of the embedded code block that contains only the Response.Write(…) statement. This is the simplest way to display information such as a single string, an int variable, or a constant.
For example, the following sample code displays the current time:
Remember that the displaying expression cannot be used in the attributes of server controls. This is because the .NET Framework directly compiles the whole expression instead of the displaying content as the value to the attribute.
For more information about how to display information from ASP.NET, visit the following MSDN Web site:
<%@ ... %> directive expressionThe directive expression is the syntax that specifies settings that are used by the page and by user control compilers when they process ASP.NET Web Form (.aspx) pages and User Control (.ascx) files.
The ASP.NET page framework supports the following directives:
For more information about directive syntax, visit the following MSDN Web site:
Collapse this tableExpand this table
<%# ... %> data-binding expressionThe data-binding expression creates binding between a server control property and a data source when the control’s DataBind method of this server control is called on the page.
The following example shows how to use the data-binding expression to bind the string from a function to the Text property of a label:
For more information about data-binding expression syntax, visit the following MSDN Web site:
<%$ ... %> expression builderThe expression builder is used to set values of control properties based on the information that is contained in an application's configuration or resource files. The following is the basic syntax of the expression builder:
<%$ Expression Prefix: Expression Value %>The dollar sign ($) indicates to ASP.NET that the following expression is an expression builder. The expression prefix defines the kind of expression, such as AppSettings, ConnectionStrings, or Resources. Additionally, you can create and define your own expression builder. The expression value that follows the colon (:) is what ASP.NET will actually use as the value of a certain property.
The following demo shows how to use the expression builder to obtain the copyright of a Web site from the AppSettings node in the Web.config file and how to then set the copyright information as the value of the Literal’s Text property.
The AppSettings node in Web.config file:
The expression builder in the ASP.NET Web Form page:
For more information about ASP.NET expressions, visit the following MSDN Web site:
<%-- ... -- %> server-side comments blockThe server-side comments block lets developers embed code comments in any location of the HTML source of ASP.NET Web Form pages (except for within <script> code blocks). Any content between the opening and closing tags of the server-side comments block will not be processed on the server or rendered on the resulting page.
The following code example shows how to use the server-side comments block in an ASP.NET page:
For more information about server-side comments, visit the following MSDN Web site:
Contact us for more help
Connect with Answer Desk for expert help.