如何为自定义控件定义默认“TagPrefix”

时间:2021-10-16 07:38:37

I have a number of custom controls that I am trying to enable designer support for. The signature looks something like the following:

我有许多自定义控件,我正在尝试启用设计器支持。签名看起来如下所示:

[ToolboxData("<{0}:MyDropDownList runat=\"server\" CustomProp="123"></{0}:MyDropDownList>")]
public class MyDropDownList: DropDownList
{
   ... code here
}

This works fine, but when I drag a control onto the page from the toolbox, the TagPrefix that gets added is "cc1":

这很好,但是当我从工具箱中将控件拖到页面上时,添加的TagPrefix是“cc1”:

<%@ Register Assembly="DBMClientPortal.Controls" Namespace="DBMClientPortal.Controls"
    TagPrefix="cc1" %>

Obviously it is somewhat irrelevant what that TagPrefix is... it works as it stands, but I figured I must be able to change it somehow and curiosity got the better of me...

显然,TagPrefix是什么有点无关紧要...它的工作原理,但我想我必须能够以某种方式改变它,好奇心让我变得更好......

Anyone know how to define what the TagPrefix will be set to when dragging a custom control onto a page in visual studio?

任何人都知道如何定义在Visual Studio中将自定义控件拖到页面上时TagPrefix将被设置为什么?

Thanks, Max

谢谢,马克斯

2 个解决方案

#1


6  

It looks something like this:

它看起来像这样:

[assembly:TagPrefix("MyControls","RequiredTextBox")]

and here's some more info about it.

这里有一些关于它的更多信息。

#2


1  

FYI, the TagPrefix attribute is only a suggestion to Visual Studio and other designer tools. If the user already has your namespace registered to a different tag prefix then it is free to use that tag prefix. Also, if your suggested tag prefix is already in use and points to a different namespace, the Visual Studio will use an auto-generated tag prefix instead.

仅供参考,TagPrefix属性仅是对Visual Studio和其他设计器工具的建议。如果用户已将您的命名空间注册到不同的标记前缀,则可以使用该标记前缀。此外,如果您的建议标记前缀已被使用并指向不同的命名空间,则Visual Studio将使用自动生成的标记前缀。

However, the odds of either one of those happening is fairly small if you choose a tag prefix that is based on your product's or company's name.

但是,如果您选择基于产品或公司名称的标记前缀,则其中任何一个发生的几率都相当小。

#1


6  

It looks something like this:

它看起来像这样:

[assembly:TagPrefix("MyControls","RequiredTextBox")]

and here's some more info about it.

这里有一些关于它的更多信息。

#2


1  

FYI, the TagPrefix attribute is only a suggestion to Visual Studio and other designer tools. If the user already has your namespace registered to a different tag prefix then it is free to use that tag prefix. Also, if your suggested tag prefix is already in use and points to a different namespace, the Visual Studio will use an auto-generated tag prefix instead.

仅供参考,TagPrefix属性仅是对Visual Studio和其他设计器工具的建议。如果用户已将您的命名空间注册到不同的标记前缀,则可以使用该标记前缀。此外,如果您的建议标记前缀已被使用并指向不同的命名空间,则Visual Studio将使用自动生成的标记前缀。

However, the odds of either one of those happening is fairly small if you choose a tag prefix that is based on your product's or company's name.

但是,如果您选择基于产品或公司名称的标记前缀,则其中任何一个发生的几率都相当小。