The Structure of an ASP.NET Page ASP.NET頁面的結(jié)構(gòu)(6部分) Directives指示 <%@ .... %>兩大類Page/Import Page Directives頁指示 語言指示<%@ Language="C#" %> <%@ Page Language="C#" %> 跟蹤指示<%@ Trace="True" %> <%@ Page Trace="True" %> Trace class的方法: Write() and Warn().兩種方法都可輸出文字,區(qū)別在于方法1是正常顯示,文法2是紅色顯示. 示例頁面 Listing 1.11 Trace.aspx 調(diào)試指示<%@ Debug="True" %> <%@ Page Debug="True" %> Import Directives導(dǎo)入指示 默認(rèn)情況下,頁面會自動導(dǎo)入了一部分命名空間,如果需要其它命名空間,必須顯式的導(dǎo)入,如導(dǎo)入System.Web.Mail命名空間 <%@ Import Namespace="System.Web.Mail" %> 示例頁面Listing 1.12 ImportNamespace.aspx Code declaration blocks 代碼聲明部分 代碼聲明區(qū)包含了頁面對應(yīng)的應(yīng)用程序邏輯,所有的公用變量定義,子過程,函數(shù).包含有類似<Script Runat="Server">的標(biāo)記. 參數(shù)1 Language表示語言類型,可選參數(shù)2 SRC可以指向一個(gè)外部文件. <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控制區(qū) 包含有類似<form Runat= "Server">的標(biāo)記.可以分區(qū)到整個(gè)頁面各區(qū)域. 子元素包含有類型<span Runat="Server"> and <ASP:Label Runat="Server"/>的標(biāo)記. 對于<form Runat="Server">的標(biāo)記是很重要的,表示你不可能在一個(gè)頁面中包含多個(gè)Form. Code render blocks 代碼塊 有inline code and inline expressions 兩種用<% %> <% strSomeText = "Goodbye!" %> The value of strSomeText is: <%=strSomeText%> Server-side comments 服務(wù)端注釋 用<%-- xxxx --%>表示. <%-- This is inside the comments <asp:Label Text="hello!" Runat="Server" /> <%= strSomeText %> --%> Server-side include directives 服務(wù)端包含指示 可以包含外部文件,文件可以是本地的也可以是遠(yuǎn)程的.所有的包含代碼被先執(zhí)行. <!-- #INCLUDE file="includefile.aspx" --> <!-- #INCLUDE virtual="/myDirectory/includefile.aspx" --> 不合法的 <!-- #INCLUDE file="<%=myVar%>" --> 注意:可以替代服務(wù)端包含指示的是用戶控件. Literal text and HTML tags 文字及HTML標(biāo)記區(qū) 可以在這部分包含ASP.NET的HTML標(biāo)記, 靜態(tài)部分可以使用舊的HTML標(biāo)記和文字.可以使用 LiteralControl 類. <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>
|