0
我有這段代碼。它應該實現我的自定義驗證,但它不起作用:爲什麼我不能在ASP.NET中使用JavaScript創建自定義驗證器?
<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" />
我用Firebug,但沒有結果。
您的代碼似乎是工作時ListBox1的是空 – Waqas
錯誤的標籤!不是java,而是javascript ......人們可以如何混合這些東西 – javagirl
@javagirl:可能與「Java」在兩方面有關。 –