开发者

Why can’t I create a custom validator using JavaScript in ASP.NET?

开发者 https://www.devze.com 2023-03-23 09:59 出处:网络
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\">

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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消