在ASP+ 中我們如何使用 Class 而不是組件

來源:互聯網
上載者:User
asp+ 在ASP+ 中我們如何使用 Class 而不是組件
/*
   豆腐製作 都是精品
   http://www.asp888.net 豆腐技術站
   如果您轉貼 本文  請 保留著作權資訊
   更多文章 都在  豆腐技術站
*/
asp+ 中我們有辦法使用 先行編譯(pre-release)的代碼 而不是 已經編譯好的 二進位代碼(build-in) 的組件
下面我們來看看一個例子

你可能會用到類似下面的代碼:
    <%@ Assembly src="test.cs" %>    // Compile C# class
    <%@ Assembly src="test.vb" %>    // Compile VB class
在 代碼的最上方 我們使用這樣的 代碼告訴編譯器 把 檔案中包含的 Class 編譯到asp+ 的頁面中

test.cs:

public class MyClass {

   public string SaySomething() {
      return "豆腐製作 都是精品";
   }
}
test.vb:
public class test
   readonly Property SaySomething() as string
      get
         SaySomething="豆腐製作 都是精品"
      end get
   end Property
end class

test.aspx:

<%@ Assembly Src="test.vb" %>

<html>
   <script language="VB" runat=server>

      Sub Page_Load(Sender as Object, E as EventArgs)

          Dim Temp as New test
          lblMsg.Text = temp.SaySomething()

      End Sub

   </script>

   <body>
      <asp:label id="lblMsg" runat=server/>
   </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.