日期:2014-05-18  浏览次数:20523 次

那个验证控件可以验证image的Url不能为空
能个例子么

------解决方案--------------------
你可以用CustomValidator验证控件

类似于:

HTML code

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