ASP.NET組件設計學習之創(chuàng)建工程庫
ASP.NET組件設計學習之創(chuàng)建工程庫是如何的呢?讓我們開始吧:
學習創(chuàng)建工程庫、在自己的項目中應用
ASP.NET組件設計學習之創(chuàng)建工程庫1、 啟動VS200X
ASP.NET組件設計學習之創(chuàng)建工程庫2、 選擇新建解決方案
ASP.NET組件設計學習之創(chuàng)建工程庫3、 選擇缺省的方案類型,選擇 Web控件庫。Web控件庫不需要web站點,基本上是一個DLL類型庫
ASP.NET組件設計學習之創(chuàng)建工程庫4、 輸入自己的類型庫的名稱,譬如ASPCTLLib之類的。這個決定了namespace和以后其他工程使用此庫的引用庫名。
ASP.NET組件設計學習之創(chuàng)建工程庫5、 系統(tǒng)自動產(chǎn)生的代碼如下:
- 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﹥
- /// 將此控件呈現(xiàn)給指定的輸出參數(shù)。
- /// ﹤/summary﹥
- /// ﹤param name="output"﹥ 要寫出到的 HTML 編寫器 ﹤/param﹥
- protected override void Render(HtmlTextWriter output)
- {
- output.Write(Text);
- }
- }
- }
ASP.NET組件設計學習之創(chuàng)建工程庫6、 AssemblyInfo.cs的介紹
ASP.NET組件設計學習之創(chuàng)建工程庫7、 編譯此工程得到ASPCTLLIb.dll
ASP.NET組件設計學習之創(chuàng)建工程庫8、 其他項目引用
如何引用自己建立的Web控件庫
1、 打開/新建一個asp.net項目
2、 引用ASPCTLLib.dll,將會在引用中出現(xiàn)aspctllib,同時將之前的dll文件復制到當前工程的目錄
3、 將自己的Web控件庫中控件加入toolbar的選項卡:右擊選項卡,自定義工具箱,選擇.net框架組件,瀏覽,找到aspctllib.dll加入,即可看到名為WebCustomControl1的組件存在于工具箱
4、 打開自己的aps.net web 項目,選擇一個web窗體,可以將自己的控件加入到其中。缺省的設計時此控件會顯示:[WebCustomControl1 ” WebCustomControl1”]。
5、 選中窗體中的此控件,打開屬性進行編輯,基本上缺省的設計控件僅有一個Text屬性屬于定制屬性,輸入特定文字。
6、 編譯,瀏覽察看效果。
ASP.NET組件設計學習之創(chuàng)建工程庫的步驟就向你介紹到這里,希望對你學習ASP.NET組件設計之創(chuàng)建工程庫有所了解。
【編輯推薦】