Question ASP..NEt Custom Masterpage & Inheritance

niceastham

Member
Joined
Mar 18, 2011
Messages
11
Programming Experience
1-3
Hi All

Here is the situation.....

I am working on multiple projects and want to create a shared master page.

I wanted to do this by creating a class in a base assembly that all projects would reference and therefore this masterpage would exist. The reason for this is that I would like a consistent layout across multiple sites, and I saw that the masterpage actually inherits from a control.

My thoughts were to code as if this was a custom server control.... ie override the createchildcontrols sub and create various panels and menus in code whilst inheriting the System.Web.UI.MasterPage class. I would then create one master page in each site and make that inherit my custom master page class. I assumed that this would work fine and that those controls would then be added to each page correctly... which they are.... but after the content template container.

So.....

Am i being stupid..... it is Friday afternoon and missing something obvious?
Should i use something else other than me.controls.add() when adding controls (such as a panel) to my custom master page?
Can this actually be done?

Sample code is below - basic example of what i am trying to do. I would then like to create a master page in each site which inherits from MyMasterPage but actually has no markup, as i was hoping this would do it. However this renders after the contents of a page.


Public Class MyMasterPage
Inherits System.Web.UI.MasterPage

Private cHeaderPanel As Panel

Protected Overrides Sub CreateChildControls()
MyBase.CreateChildControls()
cHeaderPanel = new Panel
With cHeaderPanel
.BackColor = System.Drawing.Color.Black
End With
End Sub

End Class



Thanks in advance and hope i made sense!

Nic
 
Top Bottom