Introduction to ASP. net inline expressions in the. NET Framework
Http://topic.csdn.net/u/20090415/15/f1e44c74-5257-4849-83f4-9c7603a9ec29.html
<% @ Indicates: Reference
<% # Indicates binding
<% = Indicates: Value
<% = Variable name %>
<% # Field name to be bound %> or <% # Call the background method %>
<% Inline code %> is called inline code...
<% = Inline expression %> is called an inline expression...
<% # Data-binding expression %> is called a data binding expression...
Http://blog.csdn.net/mails2008/article/details/6127114
This article describes the following ASP. NET inline expressions:
- <%... %>
- <% =... %>
- <% @... %>
- <% #... %>
- <% $... %>
- <% --... %>
- <% @... %>
<%... %> Embedded code block
Embedded code blocks are used to retain the traditional
ASP backward compatibility. The code in the block can execute programming statements and call functions in the current page class during page rendering.
The following example shows an ASP. NET page with the Microsoft Visual Basic.net code displayed in the result of a loop in the sample embedded code block:
<%@ Page Language="VB" %>
An embedded code block always corresponds
HTML sources are mixed because it is difficult to read and maintain these developers.
For more information about embedded code blocks in ASP. NET web pages, visit the following Microsoft Developer Network (MSDN) Website:
Http://msdn.microsoft.com/en-us/library/ms178135.aspx
Back to Top
<% =... %> Display expression
In <
% =... %> The display expression is include only Response. Write (...) Statement embedded code block is equivalent. This is the easiest way to display information (such as a single string, an int variable, or constant.
For example, the following code example shows the current time:
<%@ Page Language="VB" %>
Remember that the server control attributes cannot be used in the display expression. This is because in. net
Framework directly compiles rather than displaying the property value of the content. The value is used as the whole expression.
For details about how to display information in ASP. NET, visit the following MSDN Website:
Http://msdn.microsoft.com/en-us/library/6dwsdcf5.aspx
Back to Top
<% @... %> Command expression
Command expressions are used to process pages and user control compilers.
Syntax for setting ASP. NET Web forms (. aspx) pages and user controls (. ascx) files.
The ASP. NET page framework supports the following commands:
@ Page |
Defines page-specific attributes used by ASP. NET page analyzer and compiler. It can be included only in the. aspx file. * You can use the command name only on the ASP. NET Web forms page. |
@ Control |
Defines control-specific attributes used by ASP. NET page analyzer and compiler. It can only be contained in the. ascx file (user control. * The command name, which can only be in the user control file. |
@ Import |
Explicitly import a namespace to a page or user control. |
@ Implementation |
Declares a page or user control to implement the specified. net Framework interface. |
@ Registration |
Associate the alias with the namespace and class name. This allows user controls and custom server controls to be included in the requested page or user control during rendering. |
@ Assembly |
Link the assembly to the current page during compilation. It makes all the classes and interfaces of the Assembly available on the page. |
@ Master |
Identifies the ASP. NET master page. |
@ WebHandler |
Identifies an ASP. NET IHttpHandler page. |
@ PreviousPageType |
Provides a method to obtain the strong type of the previous page, such as throughPreviousPageAttribute access. |
@ MasterType |
Assign a class nameMasterASP. NET page of the property. Provides a method to create a strong reference for ASP. NET master pages. |
@ OutputCache |
Control the page of the output cache policy or user control in declarative mode. |
@ Reference |
Link to the current page or user control in a declarative manner. |
For more information about the command syntax, see the following
MSDN Website:
Http://msdn.microsoft.com/en-us/library/xz702w3e.aspx
Back to Top
<% #... %> Data binding expression
On the page, callDataBindMethod, the data binding expression creates the binding between the server control attributes and the data source.
The following example shows how to bind the string of the function of the Data Binding expression to the tagTextAttribute:
<%@ Page Language="VB" %> <script runat="server"> Protected Function SayHello() As String Return "Hello World" End Function Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) lblHello.DataBind() End Sub </script>
For more information about the data binding expression syntax, see the following
MSDN Website:
Http://msdn.microsoft.com/en-us/library/bda9bbfx.aspx
Back to Top
<% $... %> Expression Generator
To set the value of the control property based on the application configuration or the information contained in the resource file, use the expression generator. The basic syntax of expression generator is as follows:
<% $ Expression Prefix: expression %> Value
Dollar sign
($) Indicates that the expression below ASP. NET is an expression generator. Expression prefix definition as shown inAppSettings,ConnectionStrings, OrResourcesThe type of the expression. In addition, you can create and define your own expression generator. The expression value (:) following the colon is the value of some attributes that ASP. NET will actually use.
The following shows how to use the expression generatorAppSettingsThe node obtains the website copyright in the Web. config file and sets the copyright information to text.TextAttribute Value.
In the Web. config fileAppSettingsNode:
<appSettings> <add key="copyright" value="(c) Copyright 2009 WebSiteName.com"/> </appSettings>
Expression generator, in
In the ASP. NET Web forms page:
<div id="footer"> <asp:Literal ID="Literal1" runat="server" Text="<%$ AppSettings: copyright %>"></asp:Literal> </div>
Related
For more information about ASP. NET expressions, visit the following MSDN Website:
Http://msdn.microsoft.com/en-us/library/d5bd1tad.aspx
Back to Top
<-%-... -- %> Server-side comment Block
The server comment block allows developers
Embedded code comments of the HTML source on the ASP. NET Web forms page (except in the <script> code block ). The server does not process any content between the start and end tags of the comments block on the server, or the content is displayed on the generated page.
The following code example demonstrates how to use the server-side comment block on the ASP. NET page:
<%@ Page Language="VB" %> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Dim strName As String strName = Session("userName") lblUserName.Text = strName End Sub </script>
For more information, see the following
MSDN Website:
Http://msdn.microsoft.com/en-us/library/4acf8afk.aspx