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

本文介绍如何创建并配置自定义ASP.NET服务器控件,包括添加ToolboxData属性及Assembly.cs文件中TagPrefix信息的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值