我遇到以下错误:
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>
我错过了什么吗?
答案 0 :(得分: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>