Mina Wissa
Mina Wissa

Reputation: 10971

Sharepoint Custom Field default template

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
        {
            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.

Upvotes: 2

Views: 593

Answers (2)

Jonathan Eckman
Jonathan Eckman

Reputation: 2077

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>

Upvotes: 1

Stu Pegg
Stu Pegg

Reputation: 1317

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

Upvotes: 0

Related Questions