I can't tell you how many times I have struggled with where to store a data item in a Check Box control. I typically need to do this when dynamically generating a series of check boxes on a page that correspond to a data item. I have used the tool tip which works ok but exposes your data to the use when the hover over the control. I have seen others manipulate part of the control ID to contain a data item but this seems problematic. Then it came to me:
using System;
namespace Utility {
public class CheckBox: System.Web.UI.WebControls.CheckBox {
public CheckBox() { }
public object Data {
get { return ViewState["Data"]; }
set { ViewState["Data"] = value; }
}
}
}
Download a sample solution.