First, one should never change the ControlCollection once created and returned by CreateControlsInstance. So the Pages
property should be defined as ReadOnly
.
Secondly, when using Visible you're telling the code generator to create a new instance of Pages
, which we don't want. So change the DesignerSerializationVisibilityAttribute from Visible
to Content
and the code generator will produce code for the contents of the object (Pages), rather than for the object itself.