设置自定义服务器控件的TagPrefix

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>

posted on 2006-07-06 22:00  stswordman  阅读(1132)  评论(0编辑  收藏  举报