0
votes

I am trying to create a Custom Field Type in SharePoint.

This control has it's value set based on another field in the same list. Because of this requirement, this field should be displayed only in the Display Mode, and not in the Edit or Create mode.

How do I ensure this?

If I just code the ASCX control to not render a field, the field will show up like this in the Edit and Create mode.

alt text http://www.mannsoftware.com/blog/Lists/Photos/121308_0204_CrossSiteLo6.png

5

5 Answers

1
votes

Generally you set the SPField.ReadOnlyField property to True to achieve the desired behaviour for any field. (Don't forget to SPField.Update accordingly!) There is an equivalent CAML attribute for list definitions, I believe.

That said, in your control class deriving from BaseFieldControl, you might just override the RenderFieldForInput() method and not call the base implementation to ensure nothing is rendered during Create or Edit. However, this would still render the field's table row in the form, which is probably not what you want. So to enforce the desired behaviour, use ReadOnlyField and override Update() in your SPField (not field control) class to always have it set to True.

0
votes

It might be easier to just change this on a list-by-list basis by going to the Advanced section of the List Settings, setting Allow management of content types? to Yes, and then editing your content type to change the value of your field to 'hidden'.

0
votes

Take a look at this blog post. I think it will give you some ideas. The concept uses different rendering templates based on the mode.

http://sharepoint.nailhead.net/2008/04/creating-rendering-template-that.html

0
votes

Did you try and set the field as hidden? http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfield.hidden.aspx

Custom FORMS pages for new item and edit item (NewForm.aspx and EditForm.aspx) would be another way to achieve this.

0
votes

Setting the ShowInEditForm and ShowInNewForm properties solved this for me.