Required Field Validator for SharePoint People Editor

Posted: February 5, 2010 in Code, Customization, javascript, People Picker

I used SharePoint People Editor control in custom asp.Net web part.I wanted to check for required field. I have tried using the property Allow Empty, but unfortunately it doesn’t work. I have used a Required field validator. Luckily it works to some extent. But the problem starts if there is any post back happening on the page. After the post back, it takes the value to be empty even if there is an entry in the control.

I got to get a javascript that  checks if the control is empty and stores the results of the validation in the IsValid property of the ServerValidateEventArgs object.

Here is the script and a custom validator we need to use to check e\whether the people editor control is empty or not.

<script type=”text/javascript” language=”javascript”>
function CheckBusinessExcellence(source, arguments)

{
if (aspnetForm.ctl00_PlaceHolderMain_pplBusinessExcellence_downlevelTextBox.value == “”)
arguments.IsValid = false;
else
arguments.IsValid = true;

}

</script>


<sharepoint:peopleeditor ValidatorEnabled=”true” autopostback=”true” rows=”1″ width=”300″ enablebrowse=”true”
id=”pplBusinessExcellence” multiselect=”False” runat=”server” />


<asp:CustomValidator ID=”rfvBusinessExcellence” runat=”server” ControlToValidate=”” ErrorMessage=”You must specify a value for this required field.” Enabled=”false” ClientValidationFunction=”CheckBusinessExcellence”>
</asp:CustomValidator>



And in a more simpler way, I found the normal Required Field validator works fine for me.

<sharepoint:peopleeditor validatorenabled=”true” allowempty=”false”  rows=”1″ width=”300″ enablebrowse=”true”
id=”pplBusinessExcellence” multiselect=”False” runat=”server” />

<asp:RequiredFieldValidator EnableClientScript=”true” ID=”rfvBusinessExcellence” ControlToValidate=”pplBusinessExcellence” runat=”server” ErrorMessage=”You must specify a value for this required field”></asp:RequiredFieldValidator>


Hope it helps.

Advertisements
Comments
  1. Where can I locate your rss? I can’t find it anywhere. I’d like to follow more of your posts.

  2. Naveen Manjunath says:

    Awsome. Saved my day.

  3. Demaemiain says:

    ovenoSoumsSox xaikalitag immemnFendy http://uillumaror.com – iziananatt Jurgetegrekly http://gusannghor.com kesaccova

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s