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 want to add a people picker to my webpart according to an event. To make it simple I want to add it when I click a button. The code would be very simple, like this:

protected void Button1_Click(object sender, EventArgs e)
    {
        PeopleEditor pe = new PeopleEditor();
        pe.ID = "CCC";
        this.Controls.Add(pe);
    }

The People Editor suddendly appears but doesn't work as expected: when I try to use it, it raised an exception:

The target 'ctl00$m$g_bbed8d1e_42f3_4288_b8ac_ba7c95856727$ctl00$CCC' for the callback could not be found or did not implement ICallbackEventHandler.

There is something I had to register to make this work? I had to handle N people picker in my page so I cannot create it invisible and then make it visibile..

Any suggestion? Thank you!

share|improve this question

2 Answers 2

up vote 0 down vote accepted

When you work with dynamically added controls these controls must be programmatically added on each postback. In your case:

  • you try to use the people picker,
  • the people picker makes postback,
  • after the postback this control does not exists anymore.

I think you should create your controls in the OnInit event (for example check if there is postback and what is the source of this postback), and think of some way to track how many controls you need to recreate.

share|improve this answer

question already asked, please look at this as i think this is what your trying to do :)

How Can I Use the SharePoint People Picker Control in my Custom Web Part?

hope it helps!

share|improve this answer
    
I think instead of posting the link just mention a little description –  Geek Jan 8 '13 at 22:39

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.