I have this piece of code. It should implement my custom validations, but it does not work:
<asp:ListBox ID="ListBox1" runat="server" SelectionMode = "Multiple">
</asp:ListBox>
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="*Required"
ClientValidationFunction = "ValidateListBox"></asp:CustomValidator>
<script type = "text/javascript">
function ValidateListBox(sender, args) {
var options = document.getElementById("<%=ListBox1.ClientID%>").options;
if (options.length > 0) {
args.IsValid = true;
}
else {
args.IsValid = false;
}
}
</script>
<asp:Button ID="Button1" runat="server" Text="Button" />
I used Firebug, but I got no result.
我修改了代码,看来您的代码中有拼写错误,我已经对其进行了编辑:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.