The Structure of an ASP.NET Page The Structure of an ASP.NET Page (6 parts)
Directives indicate <%@ .... %> two major categories of Page/Import
Page DirectivesPage instructions
Language Instructions<%@ Language="C#" %> <%@ Page Language="C#" %>
Trace Instructions<%@ Trace="True" %> <%@ Page Trace="True" %>
Methods of Trace class: Write() and Warn(). Both methods can output text. The difference is that method 1 is displayed normally and grammar 2 is displayed in red.
Sample page Listing 1.11 Trace.aspx
Debug instructions <%@ Debug="True" %> <%@ Page Debug="True" %>
Import DirectivesImport instructions
By default, the page will automatically import part of the namespace. If other namespaces are needed, they must be imported explicitly, such as importing the System.Web.Mail namespace <%@ Import Namespace="System.Web.Mail" %>
Sample page Listing 1.12 ImportNamespace.aspx
Code declaration blocks code declaration part
The code declaration area contains the application logic corresponding to the page, all public variable definitions, sub-processes, and functions. It contains tags similar to <Script Runat="Server">.
Parameter 1 Language represents the language type, and optional parameter 2 SRC can point to an external file.
<Script Runat="Server" SRC="ApplicationLogic.aspx"/>
<Script Language="C#" Runat="Server">
</Script>
<Script runat="Server">
Sub mySub
...subroutine code
End Sub
</Script>
ASP.NET controls ASP.NET control area
Contains tags similar to <form Runat="Server">. It can be partitioned into various areas of the entire page.
The child elements contain tags of type <span Runat="Server"> and <ASP:Label Runat="Server"/>.
The <form Runat="Server"> tag is very important, indicating that you cannot include multiple Forms on one page.
Code render blocks code blocks
There are two types: inline code and inline expressions, use <% %>
<% strSomeText = "Goodbye!" %>
The value of strSomeText is:
<%=strSomeText%>
Server-side comments Server-side comments
Expressed with <%-- xxxx --%>.
<%--
This is inside the comments
<asp:Label Text="hello!" Runat="Server" />
<%= strSomeText %>
--%>
Server-side include directives Server-side include directives
External files can be included, and the files can be local or remote. All included code is executed first.
<!-- #INCLUDE file="includefile.aspx" -->
<!-- #INCLUDE virtual="/myDirectory/includefile.aspx" -->
Illegal<!-- #INCLUDE file="<%=myVar%>" -->
Note: An alternative to the server-side include directive is a user control.
Literal text and HTML tags text and HTML tags area
You can include ASP.NET HTML tags in this part, and the static part can use old HTML tags and text. You can use the LiteralControl class.
<Script Runat="Server">
Sub Page_Load
Dim litControl As LiteralControl
For each litControl in Page.Controls
litControl.Text = strReverse( litControl.Text )
Next
End Sub
</Script>
<html>
<head><title>Literal.aspx</title></head>
<body>
<b>This text is reversed</b>
</body>
</html>