Skip to content

Instantly share code, notes, and snippets.

@jasonicarter
Last active July 18, 2019 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonicarter/a267c7360a6e27487bd7 to your computer and use it in GitHub Desktop.
Save jasonicarter/a267c7360a6e27487bd7 to your computer and use it in GitHub Desktop.
Determine if your ASP.NET Sitecore placeholder has any controls in it
<div class="main">
<sc:Placeholder id="myPlaceHolderID" key="myPlaceHolderKey"></sc:Placeholder>
</div>
//Problem: How do I know if my placeholder is empty?
//#1
var controlCnt = Sitecore.Context.Page.Renderings.Count(
r => r.Placeholder.IndexOf("myPlaceHolderKey", StringComparison.OrdinalIgnoreCase
) > -1);
//#2
myPlaceHolderID.Controls.Count <= 0
@townivan
Copy link

townivan commented Mar 1, 2017

Thank you! This was exactly what I needed. Appreciate it very much. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment