Note that there are some explanatory texts on larger screens.

plurals
  1. POEmbedded code blocks in masterpage and page
    primarykey
    data
    text
    <p>Well I'm some what baffled!</p> <p>'Simple problem'</p> <p>I have parts of my master page that I want to render differently depending on whether or not a ContentPlaceHolder is empty.</p> <p>So:</p> <p>I have a master page that as some code like:</p> <pre><code>&lt;% if (ContentPlaceHolder1.HasControls()) {%&gt; &lt;div id="LittleDiv"&gt; &lt;% } else { %&gt; &lt;div id="BigDiv"&gt; &lt;% } %&gt; some text &lt;/div&gt; &lt;% if (ContentPlaceHolder1.HasControls()) {%&gt; &lt;div id="Div1"&gt; yadda yadda yadda [&lt;asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"/&gt;] blah blah blah &lt;/div&gt; &lt;% } %&gt; </code></pre> <p>I have a page that has some code along the lines of:</p> <pre><code>&lt;asp:Content ID="Content1" runat="server" contentplaceholderid="ContentPlaceHolder1"&gt; &lt;% if (Model.SomeValue) { %&gt; hello! &lt;% } %&gt; &lt;/asp:Content&gt; </code></pre> <p>(note: the logic in the example page's embeded code block may be unique, for each content place holder, for each page!)</p> <p>Which seems nice however it doesn't work. The problem is as I see it (warning I might be completely wrong!). The Embedded Code Blocks are evaluated in the objects Render. A little counter intuitively the page seems to control the master. So the master page's Render is called before the pages render. This means that the master page always sees content in the page's content control.</p> <p>Is there a nice way round this? (I have a bit of a solution but it is a monstrous hack! I won't post it yet coz I don't want to influence thinking.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload