问题
Is there a way to use html5 validation (not asp:RequiredFieldValidator) on an asp:dropdownlist. I have already tried this:
<asp:DropDownList ID="ExpenseLineTypeDdl" required="required" initialvalue="0" CssClass="form-control" runat="server">
<asp:ListItem Value="0">Please Select a Type</asp:ListItem>
</asp:DropDownList>
I'd Like it to work similar to this (except for an asp:dropdownlist):
<asp:TextBox runat="server" required="required"></asp:TextBox>
回答1:
I had to get rid of {initialvalue="0"} and set the initial listitem's {value=""}:
<asp:DropDownList ID="ExpenseLineTypeDdl" required="required" CssClass="form-control" runat="server">
<asp:ListItem Value="">Please Select a Type</asp:ListItem>
</asp:DropDownList>
来源:https://stackoverflow.com/questions/31296146/html5-validation-on-aspdropdownlist