Set a RequiredFieldValidator on a SharePoint PeopleEditor control

SharePoint's PeoplePicker has pain understanding the AllowEmpty="false" property.
I found all sorts of palliative solutions including complex javascript rubbish (and even JQuery solutions).
The following is the easiest way to achieve client side validation to set the picker as requierd.

[...]
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
[...]
<SharePoint:PeopleEditor ID="PeopleEditor1"
                         runat="server"
                         SelectionSet="User"
                         MultiSelect="true"
                         MaximumEntities="2"
                         AllowEmpty="false"
                         ValidatorEnabled="true"
                         ValidationGroup="myValidationGroup" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
                            runat="server"
                            ValidationGroup="myValidationGroup"
                            ControlToValidate="PeopleEditor1$downlevelTextBox"
                            ErrorMessage="This Field is required." />

Use a RequiredFieldValidator and set the ControlToValidate to "[ControlName]$downlevelTextBox".

Comments

towkneed said…
Thank you. "$downlevelTextBox" Seems very obscure.
Kashif said…
Doesn't work in any other browser, other than IE. But at least something is better than nothing :)