asp.net - Can content page use ContentPlaceHolderID of master parent of its master page (nested master pages) -


i have 3 level nested master pages , content page. parent1 top parent, parent2 parent of parent3 , parent3 parent of content page.

i error 'cannot find contentplaceholder xxx...' xxx contentplaceholder. resides in parent2 , content page trying fill it.

can content pages use direct parent contentplaceholders or can use of higher master pages?

there 1 way there slight problem under circumstances if relying on default content placeholder.

in example, have parent1.master:

<div id="content">     <h1>lorem ipsum, parent1</h1>     <asp:contentplaceholder id="cphcontent" runat="server">         <p>i default content parent1...</p>     </asp:contentplaceholder> </div> 

and have nested parent2.master, consumes placeholder parent1:

<asp:content contentplaceholderid="cphcontent" runat="server">     <h2>i specific stuff parent2...</h2>     <asp:contentplaceholder id="cphcontent" runat="server">         <p>i default content within parent2!</p>         <p>we want create another, nested cph parent3 can use it!</p>         <p>(it seemingly ok can use same id cph<br />             in parent2 did in parent1.)</p>     </asp:contentplaceholder>    </asp:content> 

and parent3.master can consume placeholder parent2. (and provide placeholder eventual content page consume!) here is:

<asp:content contentplaceholderid="cphcontent" runat="server">     <h3>hello parent3!</h3>     <asp:contentplaceholder id="cphcontent" runat="server">         <p>i more default text in yet nested placeholder</p>     </asp:contentplaceholder>    </asp:content> 

your rendered content page this:

<div id="content">     <h1>lorem ipsum, parent1</h1>     <h2>i specific stuff parent2...</h2>     <h3>hello parent3!</h3>     <p>i plugged-in content, content page!</p> </div> 

one cool thing approach, , why might want use same names these nested cphs throughout inheritance chain, eventual content page change using of parent master pages 1 through 3 without having change else, long expected find called cphcontent consume.

ok, have seen fun part, thing mentioned might problem, if trying let of "default" text trickle down of grand-children. this, mean if content page doesn't supply content "cphcontent" placeholder, default last master page used. default parent1.master lost beyond parent2. (although use default parent3.) there may way programmatically, "out of box" seems allow asked, if can live caveat.

best of luck!


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -