Stefan Goßner

Senior Escalation Engineer for SharePoint (WSS, SPS, MOSS, SP2010) and MCMS

How To: overcome glitches with the standard field controls shipped with MOSS 2007

How To: overcome glitches with the standard field controls shipped with MOSS 2007

  • Comments 15
  • Likes

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>&nbsp;""</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

Comments
  • Thanks for the tip. My team have started evaluating MOSS as a WCM platform and we've run into issues re accessibility and poor markup (tables being used instead of CSS, spacers, etc) when using the standard controls so this technique will come in very handy. Do you know if there are plans to provide web standards-friendly controls in future (e.g. via service pack or separate download)?

  • Hi Mark,

    the same question often came up with CMS 2002 and the anwer was usually that this should be addressed with custom placeholder controls.

    So I would not expect it. But if enough requirements from customers arrive through service requests it might be that this question will be evaluated again for a service pack in the future.

    Cheers,

    Stefan

  • Not the answer I wanted to hear but thanks for replying all the same :-)

  • Oen question on RichImageFields: Is it possible to have a custom page layout with multiple PageImages on it?? I've tried many times, today, but couldn't get it to work.

    FieldName was set to PublishingPageImage, ID was set to something sifferent for each instance.

    Page 'renders' correctly in Sharepoint Designer, and when edititing the page in Sharepoint I get to see the placeholders and I can set an image to it, but When I save, all Image-fields show the exect same image, regardless of how I set them...

    Any thoughts on this?

  • Hi Iskander,

    first you need to create a content type to be used by your page layout. The page layout is just the rendering window for the content type. For each field control you add you need to have an individual column in the content type.

    Then bind the different field controls to the different columns.

    Cheers,

    Stefan

  • Hi Stefan,

    My biggest issue with controls are the web parts that come out of the box or even custom built ones. The web part is wrapped with table tags. Has anyone tried css adapters for web parts?

    thanks,

    anabhra

  • i have a question.

    i want to repalce my own modified Datetime control instead of sharepoint original datetime control. is it possible?

    Regards,

    Sed Taha

  • Hi Sed,

    if this is on a page layout you can do this.

    Best would be to derive your control from the original one.

    Cheers,

    Stefan

  • Can you show an example of this being used in an aspx page?

  • Hi Ed,

    you can only use this in a page layout - like the original field controls comming with MOSS.

    You have to open the page layout using SharePoint Designer and then you have to replace the original RichImageField control with the CorrectedRichImageField in Html View.

    Also ensure to register the namespace of your DLL and class at the top.

    Have a look in the SDK for details.

    Cheers,

    Stefan

  • Does it mather what namespace you use? Do it have to end with .SharePoint.WebControls?

  • The namespace can be different.

    Just ensure that you add the correct namespace as a reference in your page layout.

  • We came across a random issue lately where a publishing image (RichImageField) does not render correctly

  • Thanks.

    And i use RenderFieldForDisplay for my custom render.

    DisplayPattern is hard to use for me.

  • I found another way to correct this issue using only CSS.  You can check it out on my blog site.

    http://www.contentpoint.net/2009/11/24/how-to-correct-a-bug-with-the-publishing-image-field-control/

    ENJOY!

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
Raw Html Fix