Vb6 “Tag” property equivalent in ASP.Net?

后端 未结 8 1267
迷失自我
迷失自我 2021-01-12 11:19

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

相关标签:
8条回答
  • 2021-01-12 12:05

    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.

    0 讨论(0)
  • 2021-01-12 12:10

    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.

    0 讨论(0)
提交回复
热议问题