I have created a SharePoint visual webpart in SharePoint 2010 where i am using SharePoint people picker to enter the SharePoint user but when i submit.It throws an unexpected error.
here is my .ascx code
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<SharePoint:PeopleEditor AllowEmpty="false" ValidatorEnabled="true" ID="pplprimarycontact"
runat="server" MultiSelect="false" SelectionSet="User" />
and this is my code behind .ascx.cs code
protected void Button1_Click(object sender, EventArgs e)
{
string group_name;
bool user_exists_in_the_group = false;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb web = site.OpenWeb())
{
try
{
PickerEntity pe = (PickerEntity)pplprimarycontact.Entities[0];
string u1 = pe.Description;
SPUser user = web.EnsureUser(u1);
}
catch(Exception ex)
{
}
}
}
});
}
on button click it directly throws "an unexpected error has occurred" message i.e even when i am debugging putting breakpoint at the start of button click the breakpoint does not hit.
i figured out that it can be people editor issues, because when hard-coded the user as follows, it worked without throwing any error.
//PickerEntity pe = (PickerEntity)pplprimarycontact.Entities[0];
//string u1 = pe.Description;
string u1=@"domain\name";
SPUser user = web.EnsureUser(u1);
Anyone any ideas? ,
thank you