0

我面临以下错误:

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

对于以下代码(在 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>

我错过了什么吗?

4

1 回答 1

1

将 RequiredFieldValidator 移出 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>
于 2012-12-31T04:14:22.183 回答