ASP.NET組件設計Step by Step(1)

來源:互聯網
上載者:User

2004.8.1

學習建立工程庫、在自己的項目中應用

1、 啟動VS200X

2、 選擇建立解決方案

3、 選擇預設的方案類型,選擇 Web控制項陳列庫。Web控制項陳列庫不需要web網站,基本上是一個DLL類型庫

4、 輸入自己的類型庫的名稱,譬如ASPCTLLib之類的。這個決定了namespace和以後其他工程使用此庫的引用庫名。

5、 系統自動產生的代碼如下:

using System;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.ComponentModel;

 

namespace ASPCtlLib

{

     /// <summary>

     /// WebCustomControl1 的摘要說明。

     /// </summary>

     [DefaultProperty("Text"),

          ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]

     public class WebCustomControl1 : System.Web.UI.WebControls.WebControl

     {

          private string text;

          [Bindable(true),

              Category("Appearance"),

              DefaultValue("")]

         public string Text

         {

              get

              {

                   return text;

              }

              set

              {

                   text = value;

              }

         }

 

         /// <summary>

         /// 將此控制項呈現給指定的輸出參數。

         /// </summary>

         /// <param name="output"> 要寫出到的 HTML 編寫器 </param>

          protected override void Render(HtmlTextWriter output)

         {

              output.Write(Text);

         }

     }

}

 

6、 AssemblyInfo.cs的介紹

7、 編譯此工程得到ASPCTLLIb.dll

8、 其他項目引用

 

如何引用自己建立的Web控制項陳列庫

1、 開啟/建立一個asp.net項目

2、 引用ASPCTLLib.dll,將會在引用中出現aspctllib,同時將之前的dll檔案複製到當前工程的目錄

3、 將自己的Web控制項陳列庫中控制項加入toolbar的選項卡:右擊選項卡,自訂工具箱,選擇.net架構組件,瀏覽,找到aspctllib.dll加入,即可看到名為WebCustomControl1的組件存在於工具箱

4、 開啟自己的aps.net Web 專案,選擇一個web表單,可以將自己的控制項加入到其中。預設的設計時此控制項會顯示:[WebCustomControl1 ” WebCustomControl1”]。

5、 選中表單中的此控制項,開啟屬性進行編輯,基本上預設的設計控制項僅有一個Text屬性屬於定製屬性,輸入特定文字。

6、 編譯,瀏覽察看效果。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.