ASP.net 2.0 Web Forms syntax Guidance

Source: Internet
Author: User

The ASP.net Web Forms page is a declarative text file with an. aspx extension. In addition to static content, you can also use eight different syntax tag elements. This section reviews these syntactic elements and provides examples of how to use them.

Syntax for rendering code:%%> and <%=%>

The code rendering block is represented by the <% ...%> element, which allows you to control what is rendered, executed during the display phase of the Web Forms page execution. The following examples show how to use them to loop through the contents of HTML.

<%@ Page Language="VB" %>
<html>
<body>
<% Dim I As Integer
For I = 0 To 7 %>
<font size="<%=I%>"> Hello World! </font> <br>
<% Next %>
</body>
</html>

<%.%> contains code that is executed only, and an expression that contains an equal sign (<%= ...%>) evaluates the result when the content is displayed. Therefore, <%= "Hello World"%> with C # code <% Response.Write ("Hello World"); %> displays the same result.
Note that because languages need to use tags to terminate or detach statements (such as semicolons in C #), it is important to place these tags correctly.

C # code

<% Response.Write ("Hello World"); %> need to terminate the statement with a semicolon.

<%= "Hello World"; %> error: Causes "Response.Write" ("Hello World";); "

<%= "Hello World"%> do not need a semicolon.

Syntax for declaring code:

The code declaration block defines the member variables and methods that will be compiled into the page class. These blocks can be used to create page and navigation logic. The following example shows how to define the Subtract method in the

<html>
<script language="VB" runat=server>
Function Subtract(Num1 As Integer, Num2 As Integer) As Integer
Return Num1-Num2
End Function
</script>

<body>
<%
Dim Number As Integer = 100
Do While Number > 0
Response.Write("Value: " & Number & "<br>")
Number = Subtract(Number, 1)
Loop
%>
</body>
</html>

Note: Unlike ASPs, functions must be defined in <%%> blocks in ASP-all functions and global variables must be defined using the

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.