標籤:2.0 ext 開始 efault page body asp.net html5 nat
當在Visual Studio下產生ASP.NET空網頁時,預設產生代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
注釋:
在 ASP.NET 中使用程式碼後置方法來設計Web Form,可使頁代碼能夠更清晰地從 HTML 內容中分離到完全單獨的檔案中。
@page 指令如下:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
AutoEventWireUp:是否自動調用頁面事件,值為"true" or "false"。
CodeFile:指定指向頁引用程式碼後置檔案的路徑,與Inherits屬性一起使用可以將程式碼後置源檔案(Default.aspx.cs)與網頁(Default.aspx)關聯起來。
**CodeBehind:指定包含與頁關聯的類的已編譯檔案的名稱。該屬性不能在運行時使用。
**提供此屬性是為了與以前版本的 ASP.NET 的相容,以實現程式碼後置功能。在 ASP.NET 2.0 版中,應改用 CodeFile 屬性指定該源檔案的名稱,同時使用 Inherits 屬性指定該類的完全限定名稱。
Inherits(繼承):Inherits 屬性用於定義當前 Web Form所繼承的程式碼後置類別(該類是 System.Web.UI.Page 的衍生類別)。此屬性與 CodeFile 屬性一起使用。Inherits 屬性在使用 C# 作為頁面語言時區分大小寫,而在使用 Visual Basic 作為頁面語言時不區分大小寫。
<!DOCTYPE html>:HTML5標準網頁聲明
<html></html>:告知瀏覽器其為一個HTML檔案
<head></head>:檔案頭,表示檔案的開始
runat = "server":代碼提交給伺服器進行處理,runat:處理頁面,server:伺服器
##注釋為多方整理
ASP.NET空網頁產生預設代碼注釋