1 为服务器控件添加ToolboxData属性

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace WebControlLibrary1
{
    ToolboxData("<{0}:WebCustomControl runat=server></{0}:WebCustomControl>")]
     public class WebCustomControl : System.Web.UI.WebControls.WebControl
    {
    }
}

其中ToolboxData中的WebCustomControl 为服务器控件类的名称

2  为服务器控件的Assembly.cs文件添加如下信息
using System.Web.UI
[assembly:TagPrefix("WebControlLibrary1","mycontrol")]
TagPrefix属性位于System.Web.UI命名控件下,所以要引用System,Web.UI命名空间

TagPrefix原型为[assembly:TagPrefix("namespace","tagprefix")]

这杨生成的控件被拖拽到页面上就会生成一下的代码
<mycontrol:WebCustomControl1 runat="server"></mycontrol>

相关文章:

  • 2022-12-23
  • 2021-05-24
  • 2021-09-12
  • 2021-11-18
  • 2021-07-14
  • 2021-12-13
  • 2021-07-30
猜你喜欢
  • 2021-10-03
  • 2021-10-16
  • 2021-10-19
  • 2021-10-30
相关资源
相似解决方案