if (!FileUpload1.HasFile) { this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('请选择上传图片!');", true); return; } if (FileUpload1.PostedFile.ContentType.ToLower().IndexOf("image/") == -1) { this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('请上传图片!');", true); return; }