1. 指令文法
①. @page 指令
只能包含在.aspx檔案中, 文法:
<%@ Page attribute="value" [attribute="value"...]%>
②. @Control 指令
只能包含在.ascx檔案(使用者控制項)中, 文法:
<%@ Control attribute="value" [attribute="value"...]%>
③. @Import 指令
將命名空間顯式匯入到ASP.NET應用程式檔案(如網頁,使用者控制項,主版頁面)中, 同時使匯入的命名空間的所有類和介面可用於檔案.
<%@ Import Namespace="value" %>
④. @Implements
用於指示當前的ASP.NET應用程式檔案實現指定的.NET Framework介面.
<%@ Implements interface="validInterfaceName" %>
⑤. @Register
⑥. @Assembly
⑦. @Reference
⑧. @OutputCache
2. 代碼聲明塊<script runat="server" language="codelanguage" src="pathname">
代碼
</script>
例子:Code
<html>
<script language="C#" runat="server">
void EnterBtn_Click(object Src, EventArgs E)
{
Message.Text = "智者迴音:你好!" + Name.Text + ",我已經為你算了一卦,你的一生會是精彩" + "<br>" + "而幸福的一生! 但條件是:你要欣賞自己,熱愛生活並不懈進取.";
}
</script>
<body>
<center>
<form id="Form1" runat="server">
<h4>想知道你的人生是怎樣的人生嗎?</h4><br />
請輸入你的姓名:
<asp:TextBox ID="Name" runat="server"></asp:TextBox>
<asp:Button ID="Button1" Text="提交" OnClick="EnterBtn_Click" runat="server" />
<p>
<asp:Label ID="Message" runat="server"></asp:Label>
</p>
</form>
</center>
</body>
</html>
3. 代碼呈現塊
內聯代碼, 內聯運算式 (不懂啊不懂)Code
<html>
<head runat="server">
<title>示範代碼呈現快</title>
</head>
<body>
<center>
<%
for (int i = 4; i < 7; i++)
{
%>
<font size=<%=i %>>人生的意義在於創造, 而奮鬥則是一種手段.</font><br />
<% } %>
</center>
</body>
</html>