ASP.NET/你的第一個頁面
外觀
< ASP.NET
沒有一本程式設計書籍會沒有“Hello World”示例作為第一個專案/示例。
在 ASP.NET 中,建立一個快速的“Hello World”示例是無痛且簡單的。同時,我們將探索一個基本 ASP.NET 頁面的結構。
讓我們看看一個 ASP.NET 頁面的基本結構。這樣做將使我們有機會介紹與 ASP.NET 頁面編碼相關的幾個重要方面。
VB.NET
<%@ Page Language="VB" %>
<html>
<head>
<title></title>
<script runat="server">
' ASP.NET page code goes here
Sub Page_Load()
'On Page Load Run this code
End Sub
</script>
</head>
<body>
<form runat="server">
<!-- ASP.NET controls go here -->
</form>
</body>
</html>
C#
<%@ Page Language="C#" debug="true" trace="false"%>
<html>
<head>
<title></title>
<script runat="server">
// ASP.NET page code goes here
void Page_Load() {
//On Page Load Run this Code
}
</script>
</head>
<body>
<form runat="server">
<!-- ASP.NET controls go here -->
</form>
</body>
</html>
如你所見,一個 ASP.NET 頁面與一個普通的基於 HTML 的頁面有很多共同點。現在,為了製作我們的“Hello World”示例,我們只需要在上面的示例中新增一行程式碼。
VB.Net
Sub Page_Load()
'On Page Load Run this code
Response.Write ("Hello World")
End Sub
C#
void Page_Load() {
//On Page Load Run this Code
Response.Write("Hello World");
}
將原始程式碼複製到一個副檔名為 aspx 的新檔案中。然後進行上述修改。當檔案執行時,假設它被託管在與 ASP.NET 相容的 Web 伺服器上,當你訪問頁面時,你將在你的 Web 瀏覽器上看到“Hello World”字樣。