1

I am building a custom form that includes a ClientPeoplePicker control.

screenshot

When the user press the Clear button, all the fields in the forms should be reset to empty/initial status. I can do this for all the fields except the ClientPeoplePicker one.

Following is the current handler I am using for the button click event:

 protected void ClearBtn_Click(object sender, EventArgs e)
 {
     txtEmpFName.Text = string.Empty;
     txtEmpEGN.Text = string.Empty;
     dropDep.SelectedIndex = 0;
     dtStartDate.SelectedDate = new DateTime(0);

     PickerEntity picker = (PickerEntity)peoplePicker.ResolvedEntities[0];
     SPUser userInstance = oSPWeb.EnsureUser(picker.Key);
     userInstance.Name = string.Empty; // <------| This is my problem...
 }

As a reference, this is the relevant code for the picker control:

<td>
    <SharePoint:ClientPeoplePicker
         Required="true"
         ValidationEnabled="true"
         ID="peoplePicker"
         runat="server"
         InitialHelpText="Please, insert a valid User!"
         VisibleSuggestions="3"
         Width="180px"
         Rows="1"
         AllowMultipleEntities="false"
         CssClass="ms-long ms-spellcheck-true" />
 </td>
1
PeoplePickerControlName.AllEntities.Clear();
1

Just add this single line of code which will clear the PeoplePicker field.

peoplePicker.CommaSeparatedAccounts = null;

You don't need below lines in your code to clear peoplepicker

PickerEntity picker = (PickerEntity)peoplePicker.ResolvedEntities[0];
SPUser userInstance = oSPWeb.EnsureUser(picker.Key);
userInstance.Name = string.Empty;
  • I don't have a property CommaSeparatedAccounts ... – Goshky Mar 17 '16 at 10:16
  • Error 1 'Microsoft.SharePoint.WebControls.ClientPeoplePicker' does not contain a definition for 'CommaSeparatedAccounts' and no extension method 'CommaSeparatedAccounts' accepting a first argument of type 'Microsoft.SharePoint.WebControls.ClientPeoplePicker' could be found – Goshky Mar 17 '16 at 10:17
  • My bad, i thought its PeopleEditor control you are using. – P S Mar 17 '16 at 10:28
  • I have a SharePoint:ClientPeoplePicker Controll – Goshky Mar 17 '16 at 11:27
  • anyone has answer to this question?Please help – Salim Mandrekar Jan 23 '18 at 12:25
1

you can give a try

PeopleEditor.Accounts.Clear();
PeopleEditor.Entities.Clear();
PeopleEditor.ResolvedEntities.Clear();

works on fly.

  • I have a SharePoint:ClientPeoplePicker Controll – Goshky Mar 17 '16 at 11:27
  • I believe Hardik is using your ID on the ClientPeoplePicker control. This should work. – George Norberg Mar 17 '16 at 12:43
  • I have edited my answer. Please check if it works for you. – Hardik Mar 17 '16 at 12:46
  • You can check this link sharemuch.com/2011/12/04/… – Hardik Mar 17 '16 at 12:48

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.