To change the Style property, the minimum value of the control must be HtmlControl . Therefore, you need to declare the ctlHtml variable as this type.
You should also check if ctlHtml properly initialized.
I believe your code should look something like this:
public void MySub(string varInput, Panel pnl) { HtmlControl ctlHtml; switch(varInput) { case "btn": ctlHtml = new HtmlButton(); break; case "lbl": ctlHtml = new HtmlGenericControl(); break; default: ctlHtml = null; break; } if (ctlHtml != null) { ctlHtml.Style.Add("font-size", "14px"); pnl.Controls.Add(ctlHtml); } }
pswg
source share