Ok,
This seems straight forward but I am having trouble finding the solution.
I have 10 PeopleEditor
controls. Each one of the PeopleEditor
controls has a CustomValidator
and the ControlToValidate
property is set to that specific PeopleEditor
control. I assign a function to the control based on criteria.
It is possible that the same validation function is assigned to multiple CustomValidator
s which in turn means the function needs to know which ControlToValidate
control it is validating.
Is this clear?
The question is:
How do I reference the control from the ControlToValidate
property in the validation function server side c# code?
Here are similar issues but they reference client side or inline validation: How to get the 'controlToValidate' property on ClientValidationFunction? and Extract value from control in ControlToValidate property in a CustomValidator control?
UPDATE:
I have 10 of these in the .aspx
page:
<asp:Label ID="lblPeople0" runat="server" />
<SharePoint:PeopleEditor ID="edtPeople0" SelectionSet="User,SecGroup" AutoPostBack="false" CausesValidation="false" PlaceButtonsUnderEntityEditor="false" Rows="3" AllowEmpty="true" ValidatorVisible="true" runat="server" MultiSelect="true" MaximumEntities="100" ShowCreateButtonInActiveDirectoryAccountCreationMode="true" />
<asp:CustomValidator id="vldPeople0" display="Dynamic" runat="server" ErrorMessage="Error Message." ControlToValidate="edtPeople0" />
In the .aspx.cs
page, I assign the validating function like this:
vldPeople0.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(validate_ThisAndThat);
Then, I have this for the function and need to get the ControlToValidate
in order get the ResolvedEntities
from it.
/// <summary>
/// Validation function.
/// </summary>
private void validate_ThisAndThat(Object source, ServerValidateEventArgs args)
{
foreach (PickerEntity entity in (ControlToValidate).ResolvedEntities)
{
String tmpPrincipalType = (entity.EntityData["PrincipalType"]).ToString();
if (tmpPrincipalType == "User")
{
if ((entity.EntityData["DisplayName"]).ToString().Contains("aString"))
{
args.IsValid = false;
}
}
}
}