Eslam Soliman
Eslam Soliman

Reputation: 1296

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.IsValid = true;
    }
    else {
        args.IsValid = false;
    }       
}
</script>
<asp:Button ID="Button1" runat="server" Text="Button" />

I used Firebug, but I got no result.

Upvotes: 0

Views: 206

Answers (1)

Eslam Soliman
Eslam Soliman

Reputation: 1296

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

Upvotes: 1

Related Questions