方法一、在Web.config中配置,具体做法为:在Web.config文件的System.web节中添加如下代码

1

2

3

4

5

说明:assembly表示控件所在的程序集名称,namespace表示控件的命名空间,tagPrefix就是我们所要设置的项了
方法二、在使用该控件的页面添加<%Register%>指令,如下

1

说明:assembly表示控件所在的程序集名称,namespace表示控件的命名空间,tagPrefix就是我们所要设置的项了
方法三、通过Attribute来指定tagPrefix,例如在控件类添加如下Attribute

[assembly: TagPrefix("ServerControl", "scsc")]
namespace ServerControl
{
[ToolboxData("<{0}:EmailInput runat=server></{0}:EmailInput>")]
public class EmailInput : CompositeControl
{
说明:即使这样定义了,每个页面也都要添加<%Register%>指令,这样只是提供了统一的tagPrefix,实质上还是第二种方法
方法四、在控件项目中添加属性文件"Assembly.cs"中添加如下代码来自定义控件的前缀:

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Web.UI;
[assembly: TagPrefix("ServerControl","scsc")]
说明:即使这样定义了,每个页面也都要添加<%Register%>指令,这样只是提供了统一的tagPrefix,实质上还是第二种方法
最后对上面的四种方法进行说明:
- 在Web.config中进行自定义是属于应用程序级别的定义,只注册一次即可对整个应用程序有效。其他三种方法都得在引用该控件的页面添加<%Register%>指令
- asp.net定义tagPrefix的检测顺序是:assemblyInfo.cs---->控件中的attribute装饰----->webconfig中的配置,也就是说,如果这几种方法您都设置了,那么asp.net 将会采用webconfig的设置方式!相信这也是asp.net覆盖的简单道理了!
- asp.net的自带控件采用了第一种方法,即在 web.config中进行了配置,将tagPrefix配置成了asp,如果您看着不爽,可以改掉它。
转自:http://www.cnblogs.com/light5211/archive/2009/01/08/1371914.html