I have a master page that uses a user control to define most of its layout. Inside the nesting of controls in the user control, I need to add a ContentPlaceHolder. But the ContentPlaceHolder control can only be used inside .master files.
So I am trying to add the ContentPlaceHolder dynamically. I can get this to work but have to use a hack to prevent a compiler error. If I actually code and comment out the ContentPlaceHolder in the html of the master page, it prevents the compiler error Cannot find ContentPlaceHolder MasterPageMain in the master page..., but what is the right way to do this?
Here is the code in the master page that I am using to dynamically add the ContentPlaceHolder:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim cph As ContentPlaceHolder
cph = New ContentPlaceHolder
cph.ID = "MasterPageMain"
MsgsControl1 is the user control which defines the layout. This user control is defined as a property of the base class for the master page. The user control itself also is defined as a base class with the property Placeholder.
This code works and puts the user control where it should go. But it doesnt happen early enough in the compilation to prevent the compilation error. I tried using a constructor which happens earlier than Page_Init but this code couldnt resolve the reference to my base class. Does anyone know how to do this correctly or to get around the compilation error?
Thanks very much.