Search code examples
c#asp.netascx

Literal content ('</asp:RequiredFieldValidator>') is not allowed within a 'System.Web.UI.WebControls.ListItemCollection'


I am facing the following error:

Literal content ('</asp:RequiredFieldValidator>') is not allowed within a 'System.Web.UI.WebControls.ListItemCollection' 

for the following code (inside the customer.ascx):

<div class="customerTableRow">
    <div class="customerTableLeftCol">
        <asp:Label ID="CustomerCountryLabel" runat="server" Text="Country:"></asp:Label>
    </div>
    <div class="customerTableRightCol">
        <asp:DropDownList ID="CustomerCountryDropDownList" runat="server">
            <asp:RequiredFieldValidator ID="CustomerCountryRequiredFieldValidator" ControlToValidate="CustomerCountryDropDownList" runat="server" ErrorMessage="RequiredFieldValidator">
            </asp:RequiredFieldValidator>
        </asp:DropDownList>
    </div>
</div>

Am I missing anything?


Solution

  • move RequiredFieldValidator out of DropDownList

    <div class="customerTableRow">
        <div class="customerTableLeftCol">
            <asp:Label ID="CustomerCountryLabel" runat="server" Text="Country:"></asp:Label>
        </div>
        <div class="customerTableRightCol">
            <asp:DropDownList ID="CustomerCountryDropDownList" runat="server">
            </asp:DropDownList>
    
    
                <asp:RequiredFieldValidator ID="CustomerCountryRequiredFieldValidator" ControlToValidate="CustomerCountryDropDownList" runat="server" ErrorMessage="RequiredFieldValidator">
                </asp:RequiredFieldValidator>
        </div>
    </div>