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