Reputation: 14891
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
Upvotes: 0
Views: 5124
Reputation: 14891
Setting the ShowInEditForm and ShowInNewForm properties solved this for me.
Upvotes: 0
Reputation: 862
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.
Upvotes: 0
Reputation: 5993
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
Upvotes: 0
Reputation: 16770
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
'.
Upvotes: 0
Reputation: 483
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.
Upvotes: 1