开发者

Sharepoint Custom Field default template

开发者 https://www.devze.com 2023-01-03 07:42 出处:网络
I want to develop a custom lookup field for sharepoint. I created a class as the following public class CustomLookupControl:BaseFieldControl

I want to develop a custom lookup field for sharepoint.

I created a class as the following

public class CustomLookupControl:BaseFieldControl

and overided this method

protected override string DefaultTemplateName
        {
           开发者_StackOverflow中文版 get
            {
                return base.DefaultTemplateName;                    
            }
        }

but when I edit an item I find that the place of the field is empty.

my question is that I don't want to implement a custom rendering template for the field, I want to use the default template of the lookup field

how can this be achieved.


Since you are inheriting BaseFieldControl, not LookupField, the base.DefaultTemplateName will not render a lookup like you want. What you need to do is define your own template like this:

protected override string DefaultTemplateName
{
  get
  {
    return "MyCustomTemplateName";                   
  }
}

Your rendering template, which is an ascs file deployed to the root _controltemplates folder, must have the Id MyCustomTemplateName. In your template add the control, in this case LookupField and let it figure out what to render. Let it do the work for you and it will get its own DefaultTemplateName. So now your template will look like this:

<SharePoint:RenderingTemplate ID="MyCustomTemplateName" runat="server">
  <Template>
    <SharePoint:LookupField runat="server" />
    // Other custom stuff you want to add
  </Template>
</SharePoint:RenderingTemplate>


I believe you'll probably want to inherit from the Microsoft.SharePoint.WebControls.LookupField class, which is a lookup-specific descendant of the BaseFieldControl.

0

精彩评论

暂无评论...
验证码 换一张
取 消