Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What use does the *tag* attribute have in C#

I've been working with C# for over a year now, and I was wondering what other functionality the tag attribute has of a control, till now each .net control I've used (buttons, labels, textboxes, gridview, etc.) have a tag attribute that you can define.

I only know you can put something in it like a string of text.

The visual studio description says:

User-defined data associated with the control

Does the tag do anything else than that? Describe it's content? And where do you use if for? Has it been of use to any of you?

like image 945
Pieter888 Avatar asked Nov 23 '09 11:11

Pieter888


1 Answers

No, it does nothing in itself. It's up to you to use it however you want to. For example, you could use it to do a sort of simplified databinding, such that you put the user-visible text in a checkbox, and the value to store in the database (e.g. an enum value) in the tag. Then you retrieve it from the tag later on.

IME it's usually useful for "quick and dirty" scenarios where there are better ways of working, but they take a bit longer to code up - which is fine for throwaway code, but not ideal for a complex production system. That may not always be the case, of course.

like image 111
Jon Skeet Avatar answered Oct 19 '22 15:10

Jon Skeet