Saturday, February 19, 2011

How to create an ASP.NET custom control with a dash in the name?

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:

<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.

From stackoverflow
  • 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?

  • Just use camelCase, its easier to read anyways.

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

    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.

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

0 comments:

Post a Comment