I tried to return an Object instead, however that is even more general than the WebControl instance that I returned before, and therefore I could not set the general WebControl properties.
The thing is that the WebControl is too general too, and therefore when assigning e.g. TextBox properties, the compiler still thinks that it is just a WebControl and not the child (TextBox).
A way around could be to pass the control collection to the function and then add the individual controls after doing somthing like this...
Code:
TextBox textBoxControl = new TextBox();
...in each of the cases of the switch, however this is not an elegant way of doing it. There must be a way to make the compiler aware that even though the object has been declared general as a WebControl, it has now been instantiated as a TextBox or another more specific WebControl, and can therefore e.g. assign to the TextMode property of the TextBox or some other property specific to the individual controls.
Thanks anyway.
Jacob.