A long time ago (beta2 time) I published a post about the people picker control (MOSS 2007 controls - have a bit of fun with the "people editor" form control!).Lately I had many comments on that post from people who have been having issues getting the value the user selected, and asked for another demo of using the control.So here it is:
The code creates three controls - a PeopleEditor (from the Microsoft.SharePoint.WebControls namespace), a button and a textbox. The button has an click event that itirates over the users picked in the PeopleEditor and writes them to the text box. Simple
public class PeoplePickerWebPart : System.Web.UI.WebControls.WebParts.WebPart
{
{
base.CreateChildControls();
pe = new PeopleEditor();
this.Controls.Add(pe);
b = new Button();
b.Text = "Click me to see the users";
this.Controls.Add(b);
b.Click += new EventHandler(b_Click);
t = new TextBox();
t.TextMode = TextBoxMode.MultiLine;
this.Controls.Add(t);
}
void b_Click(object sender, EventArgs e)
{
foreach(string ent in pe.CommaSeparatedAccounts.Split(','))
{
t.Text += ent + Environment.NewLine;
}
}
Results:The web part as the page loads
The web part does "check names"
The web part after the click of the button
0 comments:
Post a Comment