The two sample codes in this article are mainly used to demonstrate how to use the embedded encoding method provided by ASP. NET.
Example 1
This sample code adds a code block for the for statement to the webpage, and cyclically outputs 1 ~ 6.
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">
The embedded code syntax used in this sample code is <% expression %>
Example 2
The sample code calls a function named gettime () on the current page in the embedded code block. This function returns the current time of the server.
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">
The syntax used for this embedded code is <% = expression %>.
Do not add a semicolon after gettime (); otherwise, an error will occur. Pay attention to the comparison with the previous syntax!
Finally, the programming language of the embedded code block is the default language of the current page, that is, the language specified by the Language parameter of the @ page command.
Barefoot thinking 2010-11-9