This post is an update to a previous post I had written on validating the PeopleEditor control on post back. In that particular post, I described the challenges of getting a PeopleEditor control, within a custom application page, to validate correctly as a required field on the client side (I had server side validation already in place and working correctly).
For the most part, the solution I outlined worked well, except for some situations where other controls on the page were performing their own post back (for example, a data grid in edit mode). I found that on submit of the entire form, the ASP.NET required field validator for the PeopleEditor control would kick in informing me that the field was required. However, there was a valid entry in the control so I could only conclude that the post back by some other control on the page was mucking up the view state for the PeopleEditor control and on submit the form was no longer aware that this field did in fact have a value in it.
The MSDN article found here outlines my problem exactly with the eventual solution further down in the thread. I just wanted to highlight it here because it was exactly what I needed to resolve my issue. Thank you to Jan Lange for posting his solution!
1 2 3 4 5 6 7 8 | <script language="javascript"> function CheckProjectManager(source, arguments) { if (aspnetForm.ctl00_PlaceHolderMain_ProjectManager_downlevelTextBox.value == "") arguments.IsValid = false; else arguments.IsValid = true; } </script> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <SharePoint:PeopleEditor ID="ProjectManager" AllowEmpty="false" ValidatorEnabled="true" MultiSelect="false" runat="server" SelectionSet="User" Width="200px" TabIndex="2" /> <asp:CustomValidator ID="rfvProjectManager" runat="server" ControlToValidate="" ErrorMessage="Required" Enabled="true" ClientValidationFunction="CheckProjectManager"> </asp:CustomValidator> |
Just to outline, what Jan eventually did was create a custom validator that called a javascript function to validate the control. Within that function he checks to see if the control is empty and stores the results of the validation in the IsValid property of the ServerValidateEventArgs object. Notice that he also sets the ControlToValidate property to “”.
Hope this helps!
