ie421.NET

面对技术,你别无选择,.NET世界是如此精彩,而我们要做的就是:Thinking More

博客园 首页 新随笔 联系 订阅 管理

 <script type="text/javascript">
    function CheckFile(sender,arg)
    {
        var enableExt =["jpg","gif","bmp","png"]; // add your enable extension on that
        if (arg.Value=="")
        {
            arg.IsValid =true;
        }
        else
        {
            var temp = arg.Value.split(".");
            var extension = temp[temp.length-1];
            extension = extension.toLowerCase();
            var isValid = false;
           
            for(i=0;i<enableExt.length;i++)
            {
               if (extension==enableExt[i])
               {
                    isValid=true;
               }
            }
            arg.IsValid = isValid;
        }
    }
    </script>

 

 

<asp:FileUpload ID="f1" runat="server" />
                        <asp:CustomValidator ID="CustomValidator1" runat="server"
                            ClientValidationFunction="CheckFile" ControlToValidate="f1" Display="Dynamic"
                            ErrorMessage="&lt;br/&gt;*只支持 jpg , gif , bmp , png 等图片格式"></asp:CustomValidator>

posted on 2008-08-05 17:09  ie421  阅读(229)  评论(0编辑  收藏  举报