[Code] compile embedded code for ASP. NET web pages

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.