html5 validation on asp:dropdownlist

人走茶凉 提交于 2019-12-13 07:39:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!