I have created Custom .NET controls, and I’d like to know if it’s possible, how to add a custom attribute in the web.config when you add the reference to the control.
Currently it is:
<controls>
<add tagPrefix="FOO" src="~/Controls/FooControl.ascx" tagName="Bar" />
</controls>
But what i’d like to do, is the following
<controls>
<add tagPrefix="FOO" src="~/Controls/FooControl.ascx" tagName="Bar" defaultVal="12" />
</controls>
Briefly, I want to add a custom attribute to a .NET a default ConfigurationElement (controls.add in this case) element
I know I could pass it as an attribute when I create the control or add a key in the appsettings, but I’d like to stay away from that if possible.
Thanks for your help,
No, this is not possible. The TagPrefixInfo class, which is what the
tagelement maps to is sealed and does not provide any generic properties for this purpose.If you do try to add additional properties, your application will break because asp.net will refuse to process it.
In addition, even if this was possible, it would be very difficult to see how the definition of the tag would map to the actual control that is placed on the page. I think that would get asp.net all twisted into knots trying to resolve that. This would be similar to trying to add an attribute to a
usingstatement.Based on your question, you know what most of the rest of the options open to you are.
About the only one that you didn’t mention was adding a property to the actual control that is placed on the page using the tag, i.e.