日期:2014-05-18 浏览次数:20523 次
<form id="form1" runat="server"> <script> function validate(source, arguments) { var obj = document.getElementById('<%=Image1.ClientID %>'); var trimLeft = /^\s+/; var trimRight = /\s+$/; var src = obj.getAttribute("src"); src = src.replace(trimLeft, "").replace(trimRight, ""); if (src == "") { arguments.IsValid = false; } else { arguments.IsValid = true; } } </script> <div> <asp:Image ID="Image1" runat="server" /> <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator" ClientValidationFunction="validate"></asp:CustomValidator> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </div> </form>