I want to initialize WebControl
objects, inline, but for some fields this is a little bit tricky. For instance when I try to initialize the Attributes
property of a TextBox
object like this:
using System.Web.UI.WebControls;
Panel panel = new Panel() { Controls = { new TextBox() { Attributes = { { "key", "value" } } } } };
I get the error:
Cannot initialize type 'AttributeCollection' with a collection initializer because it does not implement 'System.Collections.IEnumerable'
Any idea how could inline initialization work in this case ?