PeopleEditor
control is doing a callback to the page itself when you press "Check names" button.
In order to inject your own custom error message when "Check names" button validation resolves to false you need to inherit from PeopleEditor
control:
using Microsoft.SharePoint.WebControls;
using System.Web.UI;
using System.Xml;
namespace PeoplePickerCustomError
{
public class CustomPeopleEditor : PeopleEditor, ICallbackEventHandler
{
private const string CUSTOM_ERROR_MESSAGE = "My custom error message!";
public new string GetCallbackResult()
{
XmlDocument xmlDoc = new XmlDocument();
string originalResponse = base.GetCallbackResult();
xmlDoc.LoadXml(originalResponse);
// if there's no error return original response
if (string.IsNullOrEmpty(xmlDoc.DocumentElement.Attributes["Error"].Value))
{
return originalResponse;
}
xmlDoc.DocumentElement.SetAttribute("Error", CUSTOM_ERROR_MESSAGE);
string customResponse = xmlDoc.OuterXml;
return customResponse;
}
public new void RaiseCallbackEvent(string eventArgument)
{
base.RaiseCallbackEvent(eventArgument);
}
}
}
Then just reference it in your webpart:
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PeoplePickerHolderUserControl.ascx.cs" Inherits="PeoplePickerCustomError.PeoplePickerHolder.PeoplePickerHolderUserControl" %>
<%@ Register TagPrefix="custom" Namespace="PeoplePickerCustomError" Assembly="PeoplePickerCustomError, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c6a38d5a688a5dd0" %>
<custom:CustomPeopleEditor runat="server" ID="pePeoplePicker" />
(change the assembly information in Register
tag to match your own)