Answered by:
<menu id="MSOMenu_WebPartMenu" class="ms-SrvMenuUI"> in EMPTY web part

Question
-
I have several WP zones in a layout page like this:
<div id="_invisibleIfEmpty" name="_invisibleIfEmpty" style="padding:0;padding-top:0px;padding-bottom:20px">
<div class="WP01">
<WebPartPages:WebPartZone runat="server" Title="Right 1" id="RightColumn1" Orientation="Vertical"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>
</div></div>I am using jquery to hide some of the zones if they are empty. For example; if #WP01 is empty then hide. Which works for most of the zones.
However some 'empty' zones are rendering this in the div: <menu class="ms-SrvMenuUI" id="MSOMenu_WebPartMenu">
which means my div is no longer empty and I can't hide it.
Why does SP2010 put this into some divs and not others?
Tuesday, January 8, 2013 5:22 PM
Answers
-
Instead of using jQuery to hide the web part zones, you can use a custom code behind for your page layout. This will allow you to set the Visible property of a WebPartZone to False. This will ensure that the whole control does not render any HTML.
This blog post contains an example on how to attach a code behind
http://blogs.msdn.com/b/kaevans/archive/2011/04/02/code-behind-page-layouts-with-visual-studio-2010.aspx
- Marked as answer by Kelly Chen 2012 Thursday, January 17, 2013 6:41 AM
Tuesday, January 8, 2013 9:06 PM
All replies
-
Instead of using jQuery to hide the web part zones, you can use a custom code behind for your page layout. This will allow you to set the Visible property of a WebPartZone to False. This will ensure that the whole control does not render any HTML.
This blog post contains an example on how to attach a code behind
http://blogs.msdn.com/b/kaevans/archive/2011/04/02/code-behind-page-layouts-with-visual-studio-2010.aspx
- Marked as answer by Kelly Chen 2012 Thursday, January 17, 2013 6:41 AM
Tuesday, January 8, 2013 9:06 PM -
The answer from Jeffrey isn't actually an answer. It's way to get rid of it, but doesn't explain why SharePoint puts all this cr*p markup in an empty web part zone, its readlly annoying.
Any suggestions on why SP does this? And maybe a prettier solution to get rid of it?
Thursday, May 16, 2013 1:33 PM -
A bit late but here's my solution....
The markup SharePoint adds is put in the first empty web part zone it finds. I created a new web part zone at the top of the page layout inside a div with a styling of display:none. This way the webpart zone will never be visible, always be empty and always contain the SharePoint markup.
<div style="display:none;"> <WebPartPages:WebPartZone runat="server" Title="HiddenMenuZone"
ID="HiddenMenuZone"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </div>
- Edited by markgregs Tuesday, July 29, 2014 1:54 PM
Tuesday, July 29, 2014 1:53 PM