I\'m looking for ideas and opinions here, not a \"real answer\", I guess...
Back in the old VB6 days, there was this property called \"Tag\" in all controls, that wa
The Tag
property was always a weird wart-like thing that was useful as something off of which you could hang any data you wanted. But it wasn't strongly-typed and it didn't really make for a coherent design. The property itself just hung off the control like a weird knob. They kept it in WinForms to facilitate porting code over from VB6. The new WPF Control
class doesn't have a Tag
.
With .NET you have full object-orientation and adequate type polymorphism, so you can strongly-type whatever extra information you want to associate with a code, whether it's in a subclass or a Dictionary<Control,TValue>
.
If it's in a single Page
request and you want a general solution a Dictionary in the Page itself for each value type (e.g., Dictionary<Control,string>
and Dictionary<Control,BusinessObject>
) should be exactly what you need.
You asked about ASP.Net, but vb6 was a desktop language, and so were it's 'tagged' controls. The VBScript used for classic asp didn't really have a concept of a control.
Now in .Net, for desktop controls you can use inheritance, which is much more powerful than the old Tag property anyway. Inheritance applies to web controls as well, though you do have to be careful about using it to hold state.