views:

228

answers:

2

I am creating a page that has several user controls (similar to WebParts). Each widget has a common UI section and Content section.

I implemented this using a ParentUserControl that has the common elements and a ChildUserControl that has the content. It works great so far.

I am curious to know if I should have used a single control that has a MasterPage with common UI elements and include this MasterPage across all other children controls? (ofcourse assuming MasterPage can be used within a UC)

+1  A: 

Unfortunately MasterPages are designed to work with the Page type. The Page type is designed to use its OnPreInit method to initialize and set up the MasterPage. For this and several other reasons MasterPages cannot be used with UserControls.

What you have set up now sounds pretty good - is there a reason you want to change it?

Andrew Hare
So far what I have - the page loads parent controls that load child controls and everything happens dynamically. With dynamic loading of controls come other issues related to ViewState etc. A cleaner approach would be to load controls that dont have nested controls. I thought MP is a good fit
DotnetDude
I agree - it would be really nice to be able to use MPs with UserControls but we will have to wait until Microsoft makes that happen :)
Andrew Hare
A: 

User control is a control, which is not a independent control. I mean which won't be used by itself. It needs some other host to do something. I mean for example, A Page.

So, we can use user control in page and that renders on the browser. Master page is also user control but it has some features included than a user control. Because that problem we can't use master page on it.

Rare Solutions