Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 410603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:54:16+00:00 2026-05-12T17:54:16+00:00

Is it possible to define a control to have non-specified set of attributes? For

  • 0

Is it possible to define a control to have non-specified set of attributes? For instance:

<MyPrefix:MyControl SomeAttribute="SomeValue" runat="server"/>

I don’t want to define a property on the control class beforehand for “SomeAttribute.” I’d really just like a HashTable or some other construct like this:

"SomeAttribute" => "SomeValue"

So this control can be used in many places with attributes that are essentially made up at runtime.

I’m wonder if there’s some parsing method I can override which iterates through the attributes at parse time. I can:

  1. Look for a property with the name and set it
  2. If I don’t find such a property, put the attribute name and value into a HashTable

Possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:54:17+00:00Added an answer on May 12, 2026 at 5:54 pm

    You want to use the IAttributeAccessor interface.

    Defines methods used by ASP.NET server controls to provide programmatic access to any attribute declared in the opening tag of a server control.

    Example control:

    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    
    namespace App_Code.Controls {
        public class OutputAttributesControl : Control, IAttributeAccessor {
            private readonly IDictionary<String, String> _attributes = new Dictionary<String, String>();
    
            protected override void Render(HtmlTextWriter writer) {
                writer.Write("Attributes:<br/>");
                if (_attributes.Count > 0) {
                    foreach (var pair in _attributes) {
                        writer.Write("{0} = {1} <br/>", pair.Key, pair.Value);
                    }
                } else {
                    writer.Write("(None)");
                }
            }
    
            public String GetAttribute(String key) {
                return _attributes[key];
            }
    
            public void SetAttribute(String key, String value) {
                _attributes[key] = value;
            }
        }
    }
    

    Invocation:

    <AppCode:OutputAttributesControl runat="server" attr="value" />
    

    Output:

    Attributes:
    attr = value
    

    Caveats:

    It seems that SetAttribute is only called on attributes that can not be resolved normally. This means you’ll not see the id- or the runat-attribute in your code. Assigned properties (attr=”<%= DateTime.Now %>”) show up as an empty string. Databound properties does not show up at all in design mode, but works in normal mode (assuming that someone called DataBind, as usual).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Define a method that has many (or infinite) arguments I have the
Is it possible to define an instance method in ruby from a string (the
I have a spring bean defined outside my control. I want to set a
In general, if we have to create new control instance, we will do the
Possible Duplicate: User control javascript I defined a JavaScript function inside a user control.
Possible Duplicate: Is it possible to define enumalpha? Is there any equivalent of Java
Is it possible to define a binding between an exchange (direct or topic) and
Is it possible to define an interface (e.g. MyClass Implements MyInterface) whose method/property definitions
Is it possible to define some sort of capitalize() or toLowerCase() function when creating
It's possible to define an alias in C# like this using kvp = System.Collections.Generic.KeyValuePair<string,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.