• ASP.NET组件设计Step by Step(1)


    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、 编译,浏览察看效果。

  • 相关阅读:
    【Java】Caused by: com.ibatis.sqlmap.client.SqlMapException: There is no statement named *** in this SqlMap.
    【Mac】Mac 使用 zsh 后, mvn 命令无效
    【Java】Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 1099
    【Android】drawable VS mipmap
    【Android】java.lang.SecurityException: getDeviceId: Neither user 10065 nor current process has android.permission.READ_PHONE_STATE
    java sql解析
    java动态编译
    随想
    一致hash算法
    一致性哈希算法及其在分布式系统中的应用
  • 原文地址:https://www.cnblogs.com/jasononline/p/775437.html
Copyright © 2020-2023  润新知