3

I tried to create and use a People picker in my custom visual webpart by adding the Tagprefix and the peopleeditor control in my ascx page

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" 
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 

<SharePoint:PeopleEditor ID="ppUsers" runat="server" Width="350px" Height="35px" SelectionSet="User" />

When the solution is deployed , the People picker displays correctly but when I enter a loginname and press return key. It functions like a text control and adds a new line.

Everywhere I have searched i have found that it is to be used as shown above itself. Please help in finding out what I could be doing wrong here.

Thanks.

1

Try this,

<SharePoint:PeopleEditor AllowEmpty="true" ValidatorEnabled="true" ID="ped"
AutoPostBack="false"  EnableViewState="true"
runat="server" ShowCreateButtonInActiveDirectoryAccountCreationMode="true" SelectionSet="User"
AllowTypeIn="true" MultiSelect="false" Height="20px" Width="99%" ShowEntityDisplayTextInTextBox="true"
DoPostBackOnResolve="false" />
  • Did not work until i added the control from code behind also. – mallu coder Sep 27 '16 at 14:29
0

I had to add the control from the code only once with any ID.

This will have created a people picker control at the top of the web part. For odd some reason this enabled all other people picker controls to function correctly.

Then I hid that people picker control created from code inside a panel. If I tried to hide the control from code behind, again none of the people picker controls will work.

After that I was able to use the tag specified in the question multiple times with any different ID and use it anywhere in the design page.

Here is the code. Hope it helps.

 private PeopleEditor userSelect;//For using People picker 

    protected override void CreateChildControls()
    {
            //Create People Picker control
            userSelect = new PeopleEditor();
            userSelect.MultiSelect = false;
            userSelect.ID = "peoplepickerControl";
            userSelect.SelectionSet = "User";
            userSelect.Rows = 1;

            Panel pnlPeoplePicker = new Panel();
            pnlPeoplePicker.ID = "pnlPeoplePicker";
            pnlPeoplePicker.Style.Add("display", "none");

            //Add Control into the panel and add it to the web part
            pnlPeoplePicker.Controls.Add(userSelect);
            this.Controls.Add(pnlPeoplePicker);

            Control control = Page.LoadControl(_ascxPath);
            Controls.Add(control);
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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