Andrew Connell [MVP SharePoint]
1741 Posts |  46 Articles |  5310 Comments
.NET  |  MCMS  |  SharePoint  |  Office System
Andrew Connell's RSS Feed    
AC's Blog Quick Links
SharePoint Quick Links
Article Categories
Archives
May, 2012 (3)
April, 2012 (4)
March, 2012 (4)
February, 2012 (4)
January, 2012 (12)
December, 2011 (6)
November, 2011 (3)
October, 2011 (17)
September, 2011 (8)
August, 2011 (6)
July, 2011 (7)
June, 2011 (13)
May, 2011 (9)
April, 2011 (15)
March, 2011 (1)
February, 2011 (6)
January, 2011 (5)
December, 2010 (11)
November, 2010 (6)
October, 2010 (12)
September, 2010 (5)
August, 2010 (4)
July, 2010 (5)
June, 2010 (6)
May, 2010 (11)
April, 2010 (11)
March, 2010 (9)
February, 2010 (9)
January, 2010 (3)
December, 2009 (10)
November, 2009 (15)
October, 2009 (15)
September, 2009 (7)
August, 2009 (4)
July, 2009 (10)
June, 2009 (8)
May, 2009 (2)
April, 2009 (9)
March, 2009 (6)
February, 2009 (16)
January, 2009 (6)
December, 2008 (12)
November, 2008 (12)
October, 2008 (27)
September, 2008 (13)
August, 2008 (14)
July, 2008 (14)
June, 2008 (12)
May, 2008 (23)
April, 2008 (12)
March, 2008 (15)
February, 2008 (13)
January, 2008 (12)
December, 2007 (10)
November, 2007 (8)
October, 2007 (15)
September, 2007 (20)
August, 2007 (21)
July, 2007 (16)
June, 2007 (8)
May, 2007 (25)
April, 2007 (16)
March, 2007 (18)
February, 2007 (18)
January, 2007 (12)
December, 2006 (16)
November, 2006 (13)
October, 2006 (18)
September, 2006 (22)
August, 2006 (27)
July, 2006 (23)
June, 2006 (23)
May, 2006 (23)
April, 2006 (9)
March, 2006 (17)
February, 2006 (15)
January, 2006 (23)
December, 2005 (31)
November, 2005 (32)
October, 2005 (38)
September, 2005 (53)
August, 2005 (30)
July, 2005 (63)
June, 2005 (30)
May, 2005 (59)
April, 2005 (29)
March, 2005 (74)
February, 2005 (27)
January, 2005 (22)
December, 2004 (32)
November, 2004 (42)
October, 2004 (39)
September, 2004 (20)
August, 2004 (14)
July, 2004 (27)
June, 2004 (40)
May, 2004 (5)
April, 2004 (6)
March, 2004 (16)
February, 2004 (26)
January, 2004 (23)
December, 2003 (7)
November, 2003 (14)
October, 2003 (20)
September, 2003 (4)
Post Categories



Managed Windows Shared Hosting

Ever had the desire to hide or not render anything on a part of the page when one of your content fields is empty? If not, you will… seems I get this question all the time… it even goes so far back as the Microsoft Content Management Server 2002 days!

I had that need when building out the Critical Path Training site. Our course agenda pages need to have room for lots of modules as each class is very different. Each module contains three elements as shown in Figure 1: a required title, an optional verbose description and a bullet list of the major items covered.

7-17-2009 8-01-35 AM
Figure 1

The trick is that not all courses have the same number of modules due to varying lengths. What I needed to do was make sure we could support a ton of modules in a class, but only display those modules that had titles filled in (as that was one of the required fields). If a module didn’t have a title entered, I didn’t want to show anything for that module.

To do this I created a custom server control that had a single public property called ContentFieldToCheck. The control checked to see if this content field contained anything. If it did, it rendered it’s children as normal. Otherwise, it cleared out all the child controls which in this case, were all my module fields. Here’s what the code looks like:

7-17-2009 8-08-16 AM
Figure 2

I then wrapped this in an EditModePanel control where it was used only in display mode that SharePoint gives us OOTB (for more info check this post):

7-17-2009 8-09-12 AM
Figure 3

Technorati Tags: ,,
posted on Friday, July 17, 2009 8:14 AM

Feedback

# re: Hiding Empty Content Areas in SharePoint 2007 [WCM] Publishing Sites 7/17/2009 10:21 AM Eric
Gravatar Interesting, but wouldn't this all work better/easier as a list with a page running a data view web part for the display? Then you're not having to worry about empty items because you're only pulling list rows that exist. If there could still be empty values, then the XSL could handle the trimming.

# re: Hiding Empty Content Areas in SharePoint 2007 [WCM] Publishing Sites 7/17/2009 10:21 AM MOSSBUDDY
Gravatar Hello Andrew,
This is really gr8 post (as always). As I understand this we can use for contents in the Page Layout i.e. if we have Page field controls (as we are hiding it on per item basis basically SPContext.Current.ListItem).
How can we achieve the same thing with Webparts (basically if no list item is available to display) hide the entire webpart.

May be on the landing pages of a portal.

# re: Hiding Empty Content Areas in SharePoint 2007 [WCM] Publishing Sites 7/17/2009 10:44 AM AC [MVP MOSS}
Gravatar Eric-
No... because those aren't rows... those are content fields that are part of the page's content type.

MOSSBUDY-
You'll have to build your own Web Part. Yet aother reason why I don't like Web Parts in Publishing sites.

# re: Hiding Empty Content Areas in SharePoint 2007 [WCM] Publishing Sites 7/17/2009 7:20 PM Aaron Powell
Gravatar Haha I wrote this exact same control yesterday except I wasn't aware you could use the EditModePanel for hiding things unless it's in Display mode, so my control was checking if the page is in edit more or not.

A question though Andrew, why did you extend Panel not PlaceHolder for your control, wont Panel output a <div /> around the whole area?

# re: Hiding Empty Content Areas in SharePoint 2007 [WCM] Publishing Sites 7/19/2009 10:10 AM Ivan Wilson
Gravatar Thanks Andrew,

Can you explain a little bit more about your use of the EditModePanel? From what I can understand, you are configuring a set of controls that should never be rendered in Edit mode, only in Display mode (with additional tests done in your new WebControl logic)

If so, do you have another EditModePanel on the page with a PageDisplayMode=Edit that allows you to modify the fields in edit mode?

Is it possible to add logic to the Web Control so that it always renders the child controls when the page is in Edit mode? Would this be a way to avoid using the EditModePanel controls?

Finally - any tricks for using this with the Related Links field control? It always contains some html tags so doesn't trigger the !string.IsNullOrEmpty() test

# re: Hiding Empty Content Areas in SharePoint 2007 [WCM] Publishing Sites 7/20/2009 9:39 AM AC [MVP MOSS]
Gravatar Ivan-
There's other stuff going onin the page that I needed the EditModePanel for.

# re: Hiding Empty Content Areas in SharePoint 2007 [WCM] Publishing Sites 1/7/2010 12:22 PM Paolo
Gravatar Hi, just a by-side question: what kind of add-in for Visual Studio are you using? I've never seen before the "closing-bracket indicator", nor the namespace/class/property icon symbol next to the namespace/class/property declaration. If you wish, please feel free to send a private response using my e-mail. Thx

# re: Hiding Empty Content Areas in SharePoint 2007 [WCM] Publishing Sites 1/14/2010 11:08 AM AC [MVP MOSS]
Gravatar Paolo-
CodeRuch & Refactor Pro from DevExpress.

Post Feedback

Title:
Name:
Email:
(email will not be displayed)
Url:
Comments: 
Please add 3 and 6 and type the answer here:    
All Comments Are Filtered & Moderated
Unfortunately comment spammers are just too effecient and are constantly dirtying up blogs with irrelevant and unwanted comments trying to improve their standing on search engines. All comments on this blog are moderated. I do not censor comments, but I don't approve comments with vulger language or those soliciting products. Most of the time comments are approved within a few hours of being submitted with the only exception when I'm traveling.

Why are you asking for my email address?
The only reason I'm asking for your email address, which isn't required to submit a comment, is to provide a gravatar if you've created an account for yourself and associated your email address with a small image. If you have a gravatar created for the email address you submit, it will appear next to your comment. Otherwise nothing will appear.

What is a gravatar?
A gravatar is a "globally recognized avatar." You can get more information about gravatars, as well as create your own for free, at www.gravatar.com. You can also view my gravatar here.


Copyright © 2003 - 2012 Andrew Connell
Creative Commons License 
This work is licensed under a Creative Commons License

 
SharePoint Training
Looking for SharePoint 2010 training for developers, administrators, power users, information workers, end users & web designers? Look no further! My company, Critical Path Training offers the best SharePoint training around! We offer public & private classes both as in-person instructor-loed hands-on classes and online classes. Check out our schedule and course catalog for all the ways we can get you going on your SharePoint path!