views:

44

answers:

1

Let's say I am building a bunch of UserControls in an ASP.Net Web application, and that all those user controls inherit from a custom base class that I have created, which in turn inherits from System.Web.UI.UserControl.

Now let's say that I (via my custom base class) want the contents of each user control to be automatically wrapped in an UpdatePanel control.

How would I do this? I suspect it involves overriding the CreateControlCollection and/or CreateChildControls methods in my custom base class, but I am not sure how.

Any ideas?

A: 

The easiest thing would be to just inherit your base control from UpdatePanel. Then every child control you add to it is automatically inside of one, and you don't need to worry about which container they are being placed in.

If for whatever reason this is not possible, you could override any number of methods (OnLoad, OnPreRender, CreateChildControls, etc.) to add some logic where you move any child controls that were added to your base control's control collection, to an UpdatePanel control that your control contains.

womp