您的位置:首页 > 其它

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

2006-08-07 18:25 232 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: