Welcome to TechNet Blogs Sign in | Join | Help

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>&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

Published Thursday, March 29, 2007 12:35 AM by Stefan_Gossner

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Thursday, March 29, 2007 8:42 AM by Mark

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

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)?

Thursday, March 29, 2007 8:51 AM by Stefan_Gossner

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

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

Sunday, April 01, 2007 3:44 PM by Mark

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

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

Monday, April 02, 2007 9:44 AM by Iskander

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

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?

Monday, April 02, 2007 10:00 AM by Stefan_Gossner

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

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

Sunday, April 15, 2007 9:58 AM by Anabhra

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

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

Wednesday, May 23, 2007 8:21 AM by Sed Taha

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

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

Wednesday, May 23, 2007 8:48 AM by Stefan_Gossner

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

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

Thursday, July 26, 2007 5:19 PM by Ed

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

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

Friday, July 27, 2007 2:44 AM by Stefan_Gossner

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

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

Tuesday, August 14, 2007 4:51 AM by Stefan2

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

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

Monday, August 20, 2007 5:56 PM by Stefan_Gossner

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

The namespace can be different.

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

Saturday, October 06, 2007 2:35 PM by SharePoint Architecture & Development

# Publishing Images are shown in encoded Html/text instead of showing the image - temporary solution

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

Thursday, July 03, 2008 1:44 AM by Lori Li

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

Thanks.

And i use RenderFieldForDisplay for my custom render.

DisplayPattern is hard to use for me.

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker