如何定制Web服务器控件的TagPrefix 而不是出现cc1

80酷酷网    80kuku.com

  web|web服务|web服务器|控件
以前一直没有注意这个问题,就是自己写的ASP.NET服务器控件,即Web Custom Control。将控件拖动到页面上会有如下的标记:

 <cc1:ExListBox ID="ExListBox1" Runat="server"> </cc1:ExListBox>

在页面的页头也有这样的语法标识

<% Register tagprefix="cc1"   Namespace="namespace"   Assembly="assembly" %>

如果将这里的cc1修改为理想的TagName,那以后再拖动对应的Namespace下的控件,就均以TagName开始了。

但是,也许在Web Control 的代码中进行设置,应该就不会这么麻烦吧,还再来页面修改。 那就是需要使用TagPrefix属性(Attribute)。如下所示:

[assembly:TagPrefix("CustomControls", "custom")]
namespace CustomControls
{
 // Simple custom control
 public class ExListBox: Control
 {
//....
}

CustomControls是指命名空间,custom指希望使用的TagName

参考: MSDN  TagPrefix property

链接:http://www.ftponline.com/vsm/2003_08/magazine/columns/aspnet/

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: