I have a nested ListView on my ASP.NET Webpage, the inner ListView has an InsertItem template where I have to validate the user entries and provide warnings (using RequiredValidator and RegExpValidator and AJAX Extenders to add the call-outs). Unfortunately since the InsertTemplate is replicated for every bound item, the ValidationGroup remains the same for every independent inner ListView and the validation requires entry on all fields in all ListViews on the page, not only from the current InsertItem template.
Any idea how I can probably set the ValidationProperty to a dynamic value?
Here is (a purified and boiled-down to the problem) piece of my ASP.NET page code:
<asp:ListView ID="lstCatQualis" runat="server" ItemPlaceholderID="listQualiCats">
</LayoutTemplate>
<ItemTemplate>
</tr>
<asp:ListView ID="listQualiItems" ItemPlaceholderID="itemPlaceHolder" runat="server" DataSource='<%# Eval("Qualis") %>' InsertItemPosition="LastItem">
<InsertItemTemplate>
<tr id="quali" runat="server">
<td class="first">
</td>
<td class="qualirating">
<asp:TextBox ID="txtQualiName" runat="server" Width="250" TabIndex='1' />
<asp:RequiredFieldValidator ID="rv1" runat="server" ControlToValidate="txtQualiName"
Display="None" ErrorMessage="Bitte geben Sie Ihre Qualifikation ein."
ValidationGroup="quali"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="vco19" runat="server" TargetControlID="rv1">
</asp:ValidatorCalloutExtender>
</td>
<td class="qualirating">
<asp:TextBox ID="txtJahreErfahrung" runat="server" TabIndex='1' />
<asp:RequiredFieldValidator ID="rv2" runat="server" ControlToValidate="txtJahreErfahrung"
Display="None" ErrorMessage="Bitte tragen Sie die Anzhal der Jahre ein."
ValidationGroup="quali"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="vco2" runat="server" TargetControlID="rv2">
</asp:ValidatorCalloutExtender>
<asp:RegularExpressionValidator ID="ev2" runat="server" ErrorMessage="Geben Sie bitte eine Zahl ein."
Display="None" ControlToValidate="txtJahreErfahrung" ValidationExpression="[1-9][0-9]{0,3}"
ValidationGroup="quali"></asp:RegularExpressionValidator>
<asp:ValidatorCalloutExtender ID="vcoe2" runat="server" Enabled="True" TargetControlID="ev2">
</asp:ValidatorCalloutExtender>
</td>
<td class="qualilabel">
<asp:button ID="btnAddCatQuali" OnClick="btnAddCatQuali_Clicked" runat="server" text='Hinzufügen' TabIndex='1' ValidationGroup="quali" />
</td>
</tr>
</InsertItemTemplate>
</asp:ListView>
</ItemTemplate>
</asp:ListView>
Add an
ItemDataBoundevent handler and inside it, search for each validator and set a ValidationGroup generated with the id of the item:With a recursive function you can extend the code to look for every subclass of Validator.