I am dynamically creating controls in the overridden CreateChildControls() method. I want to add a CSS class to the HTMLTable control that is housing these controls (the controls are being added to HtmlTableCells that are being created and added to HtmlTableRows, which are then added to the HTMLTable control).
The HTMLTable control does not have a CSSClass property, though, as the other Controls do. IOW, I can do this:
boxDeptDivName = new TextBox();
boxDeptDivName.CssClass = "finaff-webform-field-input";
...but not this:
HtmlTable dynamicTable = new HtmlTable();
dynamicTable.CSSClass = "finaff-webform-table"; // <= won't compile; there is no CSSClass property for HTMLTable
So is it possible in some other way to add a CSSClass to a dynamically-created HTMLTable control?
Mr. Lister's suggestion seems a good one; but how exactly is that done. Is it something like so:
HtmlTable tbl = null;
tbl.Attributes.CssStyle.Add("class", "platypus-webform-table");
?
Assuming these are standard ASP.NET HtmlControls, they have a property Attributes, a collection to which you can add new attributes as follows:
Either
tbl.Attributes.Add("class", "platypus-webform-table");
or
tbl.Attributes["class"] = "platypus-webform-table";
Hope this helps!
By the way, wrt your update, you shouldn't try to access properties of an object that is null
;)