How To: overcome glitches with the standard field controls shipped with MOSS 2007
Some of our field controls shipped with MOSS show a quite ugly behaviour as they add an extra entry after the field. Means an extra space.
This is especially ugly for the RichImageField control as it prevents two images to show up right beside each other. This article shows that this is actually a long known issue. But this article only shows a workaround which can be compared with the approach we used in CMS 2001 before we had custom placeholder controls: to hide the control in published mode, to read the content and then to modify it in the way we want to have it.
An approach in CMS 2002 would have been to create a custom placeholder for this. So only one single change and you can benefit from this anywhere on your site.
A similar approach can easily be implemented using a custom field control in MOSS.
A field control that would fix the problem discussed in this article would look like this:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Web;
using System.Web.UI;
using Microsoft.SharePoint.Publishing.WebControls;
namespace StefanG.SharePoint.WebControls
{
public class CorrectedRichImageField : RichImageField
{
protected override void RenderFieldForDisplay(HtmlTextWriter output)
{
// create a new tempWriter to consume the output from the base class
TextWriter tempWriter = new StringWriter();
base.RenderFieldForDisplay(new HtmlTextWriter(tempWriter));
// capture the output of the base class and do the required adjustments
string newHtml = tempWriter.ToString().Replace("</span> ", "</span>");
// write out the corrected html
output.Write(newHtml);
}
}
}
If you need information about how to implement such a field control please have a look at the relevant topic in the SDK:
http://msdn2.microsoft.com/en-us/library/aa981226.aspx