ASP.NET 2.0的文法

來源:互聯網
上載者:User
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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.