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

本文介绍如何在ASP.NET中创建自定义服务器控件,包括添加ToolboxData属性以便在工具箱中显示控件,以及如何在Assembly.cs文件中使用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>

转载于:https://www.cnblogs.com/Spring/archive/2006/08/07/470212.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值