在编辑和创建模式下隐藏 SharePoint 自定义字段类型
我正在尝试在 SharePoint 中创建自定义字段类型。
该控件的值是根据同一列表中的另一个字段设置的。 由于此要求,该字段应仅在显示模式下显示,而不能在编辑或创建模式下显示。
我如何确保这一点?
如果我只是对 ASCX 控件进行编码以不呈现字段,则该字段将在编辑和创建模式下显示如下。
替代文本 http://www.mannsoftware.com/blog/Lists/Photos/ 121308_0204_CrossSiteLo6.png
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
通常,将 SPField.ReadOnlyField 属性设置为 True 即可实现任何字段所需的行为。 (不要忘记相应地进行 SPField.Update!)我相信列表定义有一个等效的 CAML 属性。
也就是说,在从 BaseFieldControl 派生的控件类中,您可能只重写 RenderFieldForInput() 方法,而不调用基本实现来确保在创建或编辑期间不呈现任何内容。 但是,这仍然会在表单中呈现字段的表行,这可能不是您想要的。 因此,要强制执行所需的行为,请使用 ReadOnlyField 并覆盖 SPField(非字段控制)类中的 Update(),以始终将其设置为 True。
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.
通过转到
列表设置
的高级
部分,设置允许管理内容类型,逐个列表地更改此设置可能会更容易?
更改为是
,然后编辑您的内容类型以将字段的值更改为“隐藏
”。It might be easier to just change this on a list-by-list basis by going to the
Advanced
section of theList Settings
, settingAllow management of content types?
toYes
, and then editing your content type to change the value of your field to 'hidden
'.看看这篇博文。 我想它会给你一些想法。 该概念根据模式使用不同的渲染模板。
http://sharepoint.nailhead.net/2008/04/创建-渲染-模板-that.html
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
您是否尝试将该字段设置为隐藏?
http://msdn.microsoft.com/en- us/library/microsoft.sharepoint.spfield.hidden.aspx
用于新项目和编辑项目(NewForm.aspx 和 EditForm.aspx)的自定义 FORMS 页面将是实现此目的的另一种方法。
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.
设置 ShowInEditForm 和 ShowInNewForm 属性为我解决了这个问题。
Setting the ShowInEditForm and ShowInNewForm properties solved this for me.