0

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.

6
  • Your code seems to be working when listbox1 is empty Commented Jul 27, 2011 at 10:34
  • wrong tags! not java but javascript... how people can mix these things Commented Jul 27, 2011 at 10:57
  • @javagirl: probably something to do with “Java” being in both terms. Commented Jul 27, 2011 at 12:08
  • @Paul Thank you very much Captain Obvious Commented Jul 27, 2011 at 12:44
  • @javagirl: You asked the question. Commented Jul 27, 2011 at 13:21

1 Answer 1

1

I have revised the code and it appears that you have spellings mistakes in your code i have edit it :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.