Note that there are some explanatory texts on larger screens.

plurals
  1. POShould I be able to understand this ContentPlaceHolder behavior?
    text
    copied!<p>My goal is to be able to define a class for the element in a child page. On my master page I have the following:</p> <pre><code>&lt;body class="&lt;myown:AttributePlaceHolder runat="server" ID="BodyCssClass"/&gt;"&gt; </code></pre> <p>The <code>AttributePlaceHolder</code> derives from <code>ContentPlaceHolder</code>, and just strips out any linebreaks and extra spaces from its content. The problem I will describe also occurs when changing the <code>AttributePlaceHolder</code> into a normal <code>ContentPlaceHolder</code> .</p> <p>Now the above stated piece of code doesn't work, and will end up in the following error:</p> <blockquote> <p>Cannot find ContentPlaceHolder 'BodyCssClass' in the master page '/Views/Shared/Site.Master', verify content control's ContentPlaceHolderID attribute in the content page</p> </blockquote> <p>When changing the above line of code into:</p> <pre><code>&lt;body class="&lt;% %&gt;&lt;myown:AttributePlaceHolder runat="server" ID="BodyCssClass"/&gt;"&gt; </code></pre> <p>It does work (note the added <code>&lt;% %&gt;</code>).</p> <p>It does the trick, just wondering if I'm missing something here.</p> <p>Just for the extra info, in my child pages I can write:</p> <pre><code>&lt;asp:Content ContentPlaceHolderID="BodyCssClass" runat="server"&gt;profile-edit someotherclass another-class&lt;/asp:Content&gt; </code></pre> <p>or even:</p> <pre><code> &lt;asp:Content ContentPlaceHolderID="BodyCssClass" runat="server"&gt;profile-edit someotherclass another-class &lt;/asp:Content&gt; </code></pre> <p>and it will be nicely printed out as:</p> <pre><code>&lt;body class="profile-edit someotherclass another-class"&gt; </code></pre> <p><strong>Edit</strong><br> As pointed out by Johan the following also works:</p> <pre><code>&lt;body class='&lt;myown:AttributePlaceHolder runat="server" ID="BodyCssClass"/&gt;'&gt; </code></pre> <p>Changes the double quotation marks into single ones.</p> <p>But than my html would also show up with single quotation marks. Call me crazy, but that just hurts me...</p> <p>I guess it has to do with the ASP.NET parsing engine, in that case should we call it a bug, or a "feature"?</p>
 

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