Why can’t I create a custom validator using JavaScript in ASP.NET?
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开发者_JAVA技巧.IsValid = true;
}
else {
args.IsValid = false;
}
}
</script>
<asp:Button ID="Button1" runat="server" Text="Button" />
I used Firebug, but I got no result.
I have revised the code and it appears that you have spellings mistakes in your code i have edit it :)
精彩评论