Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to implement AutoComplete feature for People Editor in custom field type derived from SPUserField. To do this, I have to customize both render template and field editor control (and other things).

As MSDN says, SPUSerfField is a field uses field editor control I cannot inherit from, but I need to implement switching from OOB People Editor Control to Custom People Editor.

So far, question is How can I inherit behavior of OOB UserFieldEditor to customize it in my own USerFieldEditorControl or somehow change basic behavior?

share|improve this question

2 Answers 2

If you want to just inherit PeopleEditor you can do it, because it is a public class. Pasted from reflector:

[ValidationProperty("CommaSeparatedAccounts"), SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel=true), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal), SharePointPermission(SecurityAction.LinkDemand, ObjectModel=true), AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class PeopleEditor : EntityEditorWithPicker {...}

So CustomPeopleEditor : Microsoft.SharePoint.WebControls.PeopleEditor will work just fine.

But in that linked article i can't find such a statement that you cannot inherit from it.

share|improve this answer
    
Actually, I was talking about Field Editor Control, not Render Template with PeopleEditor. There is a UserFieldEditor control for customize behavior of SPUserField. I have an idea to add this mysterious UserFieldEditor to CreateChildControls methods of my editor control I specify and add some checkboxes or whatever I need to implement switching controls behaviour. –  Bassist Oct 10 '11 at 8:06
    
@Bassist But UserFieldEditor is also inheritable (it's public) so why not? And note that you are talking about SPFieldUser no SPUserField :) –  Janis Veinbergs Oct 10 '11 at 8:12
    
Also, I doubt I should inherit from PeopleEditor because AutoComplete feature I need to implement (jQuery, for example) surely will require standard controls like textboxes. Moreover, I'll need a custom AD query logic which was implemented in PeopleEditor in horrible way, so I guess I can't use PeopleEditor. :( –  Bassist Oct 10 '11 at 8:14
    
Sorry, I'm a quite novice in SharePoint, I'm really talking about SPFieldUser :) But MSDN says I cannot inherit UserFieldEditor which is editor control for SPFieldUser. This is what I'm talking about: Your field editor control class cannot inherit from either the LookupFieldEditor or the UserFieldEditor control classes, which are the only two field editor controls that ship with SharePoint Foundation. They are not accessible from your code. –  Bassist Oct 10 '11 at 8:16
up vote 0 down vote accepted

If someone needs, here is a way to implement this feature. While we cannot declaratively use UserFieldEditor Control in our CustomFieldEditor, we still can create it programmatically. To extend UserFieldEditor props, add whatever you need declaratively in your ascx page (InpuFormSection with some RadioButs in my case) and in your code-behind make this(Don't forget implement IFieldEditor interface):

protected UserFieldEditor Editor;

bool IFieldEditor.DisplayAsNewSection
    {
        get { return false; }
    }

protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        Editor = (UserFieldEditor) Page.LoadControl("/_controltemplates/UserFieldEditor.ascx");
        Editor.DesignerInitialize();
        Controls.Add(Editor);
    }

void IFieldEditor.InitializeWithField(SPField field)
    {
        if (IsPostBack) return;
        Field = (MSTeamUserField) field;
        Editor.InitializeWithField(Field);
    }

    void IFieldEditor.OnSaveChange(SPField field, bool isNewField)
    {

        Field = (MSTeamUserField) field; // your custom field
        // apply your custom settings here
        Editor.OnSaveChange(field, isNewField); //Invoke UserFieldEditor OnSaveChange method 
    }

That's it! now you have your extended UserFieldEditorControl with all built-in settings.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.