如何使用名称中的破折号创建ASP.NET自定义控件?

时间:2022-09-02 13:29:20

I want to set up an ASP.NET custom control such that it has a custom name, specifically, with a hyphen within it, so it might look like this in markup:

我想设置一个ASP.NET自定义控件,使其具有自定义名称,特别是在其中包含连字符,因此它在标记中可能如下所示:

<rp:do-something runat="server" id="doSomething1" />

I don't mind if this syntax requires setting up a tag mapping in web.config or something to that effect, but the tagMapping element doesn't quite match up for what I'd like to do.

我不介意这种语法是否需要在web.config中设置标签映射或者其他类似的东西,但是tagMapping元素与我想做的事情并不完全匹配。

2 个解决方案

#1


1  

I wouldn't think this is possible due to the restrictions on class namings. I don't believe you can refer to a control class in markup without refering to it by name

由于对班级的限制,我不认为这是可能的。我不相信您可以在标记中引用控件类而不通过名称引用它

Is there a specific reason you need the hyphen?

是否有特定原因需要连字符?

#2


1  

John, you're right. I did some searching in Reflector and it looks like it doesn't get there:

约翰,你是对的。我在Reflector中做了一些搜索,看起来它没有到达那里:

Type ITagNameToTypeMapper.GetControlType(string tagName, IDictionary attribs)
{
    string str;
    string str2 = this._nsRegisterEntry.Namespace;
    if (string.IsNullOrEmpty(str2))
    {
        str = tagName;
    }
    else
    {
        str = str2 + "." + tagName;
    }
    if (this._assembly != null)
    {
        Type type = null;
        try
        {
            type = this._assembly.GetType(str, true, true);
        }

Implemented in System.Web.UI.NamespaceTagNameToTypeMapper, System.Web.

在System.Web.UI.NamespaceTagNameToTypeMapper,System.Web中实现。

@Jonathan: I have a specific business reason for wanting to do it this way. Oh well.

@Jonathan:我有一个特定的商业理由想要这样做。那好吧。

#1


1  

I wouldn't think this is possible due to the restrictions on class namings. I don't believe you can refer to a control class in markup without refering to it by name

由于对班级的限制,我不认为这是可能的。我不相信您可以在标记中引用控件类而不通过名称引用它

Is there a specific reason you need the hyphen?

是否有特定原因需要连字符?

#2


1  

John, you're right. I did some searching in Reflector and it looks like it doesn't get there:

约翰,你是对的。我在Reflector中做了一些搜索,看起来它没有到达那里:

Type ITagNameToTypeMapper.GetControlType(string tagName, IDictionary attribs)
{
    string str;
    string str2 = this._nsRegisterEntry.Namespace;
    if (string.IsNullOrEmpty(str2))
    {
        str = tagName;
    }
    else
    {
        str = str2 + "." + tagName;
    }
    if (this._assembly != null)
    {
        Type type = null;
        try
        {
            type = this._assembly.GetType(str, true, true);
        }

Implemented in System.Web.UI.NamespaceTagNameToTypeMapper, System.Web.

在System.Web.UI.NamespaceTagNameToTypeMapper,System.Web中实现。

@Jonathan: I have a specific business reason for wanting to do it this way. Oh well.

@Jonathan:我有一个特定的商业理由想要这样做。那好吧。