I have created a custom listform template. In this custom listform template I have removed the default <SharePoint:ListFieldIterator runat="server"/> and used my own created user control <CustomOverrideControls:CustomListFieldIterator runat="server"/>. In this user control I overwrite the CreateChildControls() method. In this method I do some logic to set some fields readonly.
public class CustomListFieldIterator : ListFieldIterator
{
protected override void CreateChildControls()
{
this.Controls.Clear();
if (this.ControlTemplate == null)
{
throw new ArgumentException("Could not find ListFieldIterator control template.");
}
for (int i = 0; i < base.Fields.Count; i++)
{
SPField field = base.Fields[i];
if (!this.IsFieldExcluded(field))
{
var child = new CompositeField();
child.ControlMode = base.ControlMode;
child.FieldName = field.InternalName;
var auditors = SPContext.Current.Web.Groups["Auditors"].ID;
bool isAuditor = SPContext.Current.Web.IsCurrentUserMemberOfGroup(auditors);
//if field is "Title", we in edit mode and user is not Auditor, make field readonly
if (field.InternalName.Equals("Title") && ControlMode == SPControlMode.Edit && !isAuditor)
{
child.ControlMode = SPControlMode.Display;
}
this.Controls.Add(new LiteralControl("<tr>"));
this.Controls.Add(child);
Controls.Add(new LiteralControl("</tr>"));
}
}
}
}
Now I have the following problem. I have some fields which are required. If let an required field empty and press on Save, I got 2 validation warnings.
Some extra information. I am using also the ItemAdded event and do some logic. I have set the ItemAdded event to Asynchronous. I have did this because the page was not refreshing after adding a new item.
<Receivers ListTemplateId="101">
<Receiver>
<Name>something</Name>
<Type>ItemAdded</Type>
<Assembly>something</Assembly>
<Class>something</Class>
<SequenceNumber>10000</SequenceNumber>
<Synchronization>Asynchronous</Synchronization>
</Receiver>
</Receivers>
What is the reason why I got 2 validation warnings on my form after saving with empty fields.
UPDATE: I have implemented the solution of Andrey Markeev, but it doesnt work. See below for some new information:
I have implemted your solution but it doesnt fix the duplicate validation warnings. I have undo all my changes like removing custom listform template and use the default template, change the itemadded event to asynchronous, remove my usercontrol and add the sharepoint listFieldIterator control back. I have the same problem. Do you see here something wrong:
This field has no duplicate validation error:
<Field ID="{A5A5CA1A-6CF4-4BA7-B650-7F06910EA0CD}" Name="RFCAppliesTo" StaticName="RFCAppliesTo" DisplayName="Betrekking op" Type="Text" Required="TRUE" />
These fields has duplicate validation erros. What is the problem?
<Field ID="{47705f89-4883-4ad5-8495-98ce1d4b5c35}" Name="RFCDescriptionCurrent" StaticName="RFCDescriptionCurrent" DisplayName="Omschrijving huidige situatie" Type="Note" NumLines="4" Required="TRUE" RichText="TRUE" RestrictedMode="TRUE" RichTextMode="FullHtml" IsolateStyles="TRUE" AppendOnly="FALSE" />
<Field ID="{F61E42BC-AEC0-43AA-9AD2-AD7B36C60B22}" Name="RFCDescriptionNew" StaticName="RFCDescriptionNew" DisplayName="Omschrijving nieuwe situatie" Type="Note" NumLines="4" Required="TRUE" RichText="TRUE" RestrictedMode="TRUE" RichTextMode="FullHtml" IsolateStyles="TRUE" AppendOnly="FALSE" />
<Field ID="{97CD7687-4F16-4AC5-9156-1F178037B5D1}" Name="RFCRisks" StaticName="RFCRisks" DisplayName="Risico's" Type="Note" NumLines="4" Required="TRUE" RichText="TRUE" RestrictedMode="TRUE" RichTextMode="FullHtml" IsolateStyles="TRUE" AppendOnly="FALSE" />
<Field ID="{D424D1B4-4CEA-4E47-B843-6B746EAD1E35}" Name="RFCDemands" StaticName="RFCDemands" DisplayName="Eisen, randvoorwaarden, afhankelijkheden" Type="Note" NumLines="4" Required="TRUE" RichText="TRUE" RestrictedMode="TRUE" RichTextMode="FullHtml" IsolateStyles="TRUE" AppendOnly="FALSE"/>