I just gave it a shot myself, and it works when I change the ControlCollection to a List<Control>.
I think the reason it's working in the page is because the ControlCollection you create is owned by the page (since you passed this into the constructor), but you're adding the controls to a Panel on the page. The problem only occurs when the control is added to the Controls collection of the same control that owns the ControlsCollection that already contains it. If you change your page to add the buttons to this.Controls instead of controlarea.Controls, you should see the same problem there, as well.
M
mdavis
@mdavis
0
Reputation
2
Posts
40
Profile views
0
Followers
0
Following
Best posts made by mdavis
This user hasn't posted anything yet.
Latest posts made by mdavis
-
RE: ASP.NET/C#: Figure THIS one out (Scoping? Doing things after rendering?)
-
RE: ASP.NET/C#: Figure THIS one out (Scoping? Doing things after rendering?)
I haven't tried this myself, but I'd suggest that you don't use a ControlCollection for this. Adding a Control to a ControlCollection appears to change the parent of the Control to the owner of the ControlCollection, and from what Reflector seems to indicate, the Control is removed from the previous parent's Controls collection in the process. It doesn't look like it's checking to see if the old parent and the new parent are the same, though, so I think it's removing the buttons immediately after adding them.
Try using an array, ArrayList, or (if you're using .NET 2.0) a List<Control> instead of a ControlCollection and see if it does any better.