65.9K
CodeProject is changing. Read more.
Home

SharePoint - Hiding Webpart div

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.80/5 (2 votes)

Dec 20, 2013

CPOL
viewsIcon

8570

How to hide the HTML tags that surround a web part (SuppressWebPartChrome)

Introduction

When adding a DataFormWebPart web part in SharePoint, the following HTML is created by SharePoint when the page is rendered (or something similar to it).

<TABLE border=0 cellSpacing=0 cellPadding=0 width="100%" TOPLEVEL>
<TBODY>
<TR>
<TD vAlign=top>
<DIV id=WebPartWPQ2 allowDelete="false" 
OnlyForMePart="true" width="100%" HasPers="true" 
WebPartID="00000000-0000-0000-0000-000000000000">
<!-- html rendered by web part -->
</DIV></TD></TR></TBODY></TABLE>
<IMG alt="" src="/_layouts/images/blank.gif" 
width=590 height=1> 

Background

This code is tested in SharePoint 2007 with the DataFormWebPart.

Using the Code

In SharePoint Designer, add the SuppressWebPartChrome="True" property:

// Example

<WebPartPages:DataFormWebPart SuppressWebPartChrome="True"  

When this property is set, the outside Table and Div tags will not be rendered by SharePoint.

This has been specifically helpful for .css renderings where embedded Divs and Tables can get thrown off.