Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How would I override the tables rendered around the webparts in the "Rich Content" area?

I have successfully removed the tables around webpartzones and their webparts but can't figure how to remove the tables around Rich Content area webparts.

I am not using the Content Editor WebPart.

The "Rich Content" area I am using is created using the PublishingWebControls:RichHtmlField.

This is the control which has content and webparts.

share|improve this question

3 Answers 3

up vote 2 down vote accepted
+100

On the same line as with the Francois, there is one excellent article from MVP Waldek Mastykarz explaining not only how-to, but as well implication of changing TABLES into DIVs.

See here http://blog.mastykarz.nl/removing-web-parts-tables-sharepoint-2010/

Hope it helps, C:\Marius

share|improve this answer

If your table has some unique class or id you can consider using jQuery to dynamically remove any of the DOM element using simple jQuery script

Consider doing it through jQuery

share|improve this answer
    
I want to do this server side without WPS. –  iambriansreed Mar 29 '12 at 19:52

You can use the ChromeType : none to remove most of the tables but if you want to go further, you'll need one or more control adapter (custom development) that will take care of removing most of the tables generated by the webpart zones and the webparts

For the adapter, you can use the ones from the Accessibility Kit (AKS) or the one (also based on it) adapted by David Schneider

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;

/// WebPartZone Adapter
/// Created by David Schneider
/// http://blog.sharepoint.ch
/// Based on AKS

namespace AKSAdapters
{
  public class AKS_WebPartZone_Adapter : System.Web.UI.Adapters.ControlAdapter
  {
      protected override void Render(HtmlTextWriter writer)
      {
          bool inEditMode = false;
          System.Web.UI.WebControls.WebParts.WebPartZone wpz = Control as System.Web.UI.WebControls.WebParts.WebPartZone;
          if (wpz != null && wpz.Attributes["tableless"] != null)
          {
              SPWebPartManager swpm = (SPWebPartManager)SPWebPartManager.GetCurrentWebPartManager(wpz.Page);
              inEditMode = !swpm.GetDisplayMode().AllowPageDesign;
          }
          if (inEditMode)
          {
              // Render the WebPartZone
              writer.Indent++;
              writer.AddAttribute(HtmlTextWriterAttribute.Id, wpz.ID);
              if (!String.IsNullOrEmpty(wpz.CssClass))
              {
                  writer.AddAttribute(HtmlTextWriterAttribute.Class, wpz.CssClass);
              }
              if (wpz.LayoutOrientation == System.Web.UI.WebControls.Orientation.Horizontal)
              {
                  writer.AddAttribute(HtmlTextWriterAttribute.Class, "AspNet-WebPartZone-Horizontal");
              }
              else if (wpz.LayoutOrientation == System.Web.UI.WebControls.Orientation.Vertical)
              {
                  writer.AddAttribute(HtmlTextWriterAttribute.Class, "AspNet-WebPartZone-Vertical");
              }
              writer.RenderBeginTag(HtmlTextWriterTag.Div);
              writer.Indent++;

              // Render the web parts
              if (wpz.WebParts.Count > 0)
              {
                  WebPartCollection wpColl = new WebPartCollection(wpz.WebParts);

                  foreach (System.Web.UI.WebControls.WebParts.WebPart wp in wpColl)
                  {
                      writer.WriteLine();
                      writer.AddAttribute(HtmlTextWriterAttribute.Class, "AspNet-WebPart");
                      writer.RenderBeginTag(HtmlTextWriterTag.Div);

                      wp.RenderControl(writer);
                      writer.RenderEndTag(); // Div
                      writer.Indent++;
                  }
              }
              writer.RenderEndTag(); // Div

              writer.Indent--;
              writer.WriteLine();
          }
          else
          {
              // If we are editing the page --> render the web part as usual.
              base.Render(writer);
          }
      }
  }
}

and to isolate it to the content editor web part, you can bind a control adapter to just that webpart

<browsers>
    <browser refID="Default">
        <controlAdapters>
            <adapter
controlType="Microsoft.SharePoint.WebPartPages.ContentEditorWebPart"
adapterType="ProjectName.SharePoint.Adapters.ContentEditorWebPartAdapter" />
        </controlAdapters>
    </browser>
</browsers>

And override the render but I'm not sure that the wrapping table mentioned is generated at the render process.

Kindly

share|improve this answer
    
Yes, the exact control adapter is what I am looking for. –  iambriansreed Mar 23 '12 at 13:36
    
I have updated my reply to point to the adapter that I based my development on. Edit : saw that you updated your question as well so you already know that kind of stuff. What about removing the final ones injected by the CEWP through a little bit of JQuery ? I never noticed the CEWP is wrapping its content in another table but I'm relying on publishingHtml field in my content type and try to discard the CEWP as much as possible –  Francois Verbeeck Mar 23 '12 at 14:03
    
I am not using the CEWP. When I refer to the "Rich Content" area I am using the PublishingWebControls:RichHtmlField. This is the control which has normal content and some webparts. –  iambriansreed Mar 23 '12 at 14:18
    
I think Waldek wrote something about it. I would anyway try the jquery road since it's quite easy to remove wrapping elements if you know where to look at (if and your adapter is already wrapping or identifying your webparts with classes or id, it should be easy). –  Francois Verbeeck Mar 23 '12 at 14:30
    
I have to to this server side. I hate that jump in formatting. –  iambriansreed Mar 23 '12 at 14:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.