我的网页上有一个Dropdownlist,如下所示. asp:DropDownList runat="server" ID="cboNoOfSubjects" AutoPostBack="true" CssClass="textEntry" width="80%" onclick="javascript:shouldsubmit=false;" ValidationGroup="valCourseFees" asp:ListIt
<asp:DropDownList runat="server" ID="cboNoOfSubjects" AutoPostBack="true" CssClass="textEntry" width="80%" onclick="javascript:shouldsubmit=false;" ValidationGroup="valCourseFees"> <asp:ListItem Value="0">-Select-</asp:ListItem> <asp:ListItem Value="1">1</asp:ListItem> <asp:ListItem Value="2">2</asp:ListItem> <asp:ListItem Value="3">3</asp:ListItem> <asp:ListItem Value="4">4</asp:ListItem> <asp:ListItem Value="5">5</asp:ListItem> </asp:DropDownList> <font color ="red">*</font> <asp:RequiredFieldValidator ID="cboNoOfSubjects_RequiredFieldValidator" runat="server" ErrorMessage="No. of Subjects Required" ForeColor="Red" Font-Size="0.9em" ControlToValidate="cboNoOfSubjects" ValidationGroup="valCourseFees" Display="None"></asp:RequiredFieldValidator>
但验证器似乎没有发射.谁能帮我这个?
对于所有RequiredFieldValidators, InitalValue属性很重要.添加到你的,它会工作.<asp:RequiredFieldValidator ID="cboNoOfSubjects_RequiredFieldValidator" runat="server" ErrorMessage="No. of Subjects Required" ForeColor="Red" InitialValue="0" Font-Size="0.9em" ControlToValidate="cboNoOfSubjects" ValidationGroup="valCourseFees" Display="None"></asp:RequiredFieldValidator>
还有一件事需要改变,你必须设置属性Display =“Dynamic”,它将相应地显示.