I have 11 of these controls on my page, all are checkboxes. It is contained within a master page.
I can accomplish what I want like so:
generalInformation.InputAttributes.Add( "class", "SetupChecklist" );
generalInformation2.InputAttributes.Add( "class", "SetupChecklist" );
generalInformation3.InputAttributes.Add( "class", "SetupChecklist" );
Etc..
I am now trying to loop through these and do the same thing to save myself some code, but I am having a lot of trouble getting this to work properly, well I can't get it to work at all.
Can anyone give me a good way to loop through these 11 checkbox controls and add the css class SetupChecklist?
I tried this and it isn't adding the class for some reason.
protected void InitializeCheckboxes ()
{
//generalInformation.InputAttributes.Add( "class", "SetupChecklist" );
var allCheckBoxes = Page.Controls.OfType<CheckBox>();
foreach ( var c in allCheckBoxes )
{
c.InputAttributes.Add( "class", "SetupChecklist" );
}
}
I go call InitializeCheckboxes();
in the Page_Load method. It does work when I just use generalInformation.InputAttribues.Add etc.. But not when I loop through them. Any suggestions?