Is it safe to use the attributes collection of a web control to store extra data?
e.g.
DropDownList ddl = new DropDownList();
ddl.Attributes.Add("ExtraData", "SomeData");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
I would recommend against it as these attributes may be prone to tampering. Instead, you should have a list of objects on the server in which each object stores both the drop down text data as well as the extra data in it.
You can then use the index of the drop down to determine which object in your list on the server is selected. Typically, frontend controls should never contain anything but display data and indexes if you can help it. This is why datagrids have a data index column, so you can retrieve the index of the record that corresponds to the row. The record itself is not stored in the grid, only its fields are displayed.