Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7756651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:52:40+00:00 2026-06-01T12:52:40+00:00

i have a asp fileupload control on my page. how to validate the selected

  • 0

i have a asp fileupload control on my page. how to validate the selected file on client side.
validation rules:
1. file must be jpeg,png,bmp or gif.
2. file size must be within 25 kb and 2 mb.
please help.
thanks.
I Have Tried The Following Code to validate the extension

<asp:FileUpload ID="FileUpload2" runat="server"/>                    
<asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="ValidateFileUpload" ErrorMessage="Invalid file type. Only .gif, .jpg, .png, .bmp and .jpeg are allowed." ControlToValidate="FileUpload2" ValidationGroup="update">&nbsp;</asp:CustomValidator>
<script language="javascript" type="text/javascript">
    function ValidateFileUpload(Source, args) {
        var fuData = document.getElementById('<%= fuData.ClientID %>');
        var FileUploadPath = fuData.value;

        if (FileUploadPath == '') {
            // There is no file selected
            args.IsValid = false;
        }
        else {
            var Extension = FileUploadPath.substring(FileUploadPath.lastIndexOf('.') + 1).toLowerCase();

            if (Extension == "jpg" || Extension == "jpeg" || Extension == "png" || Extension == "gif" || Extension == "bmp") {
                args.IsValid = true; // Valid file type
            }
            else {
                args.IsValid = false; // Not valid file type
            }
        }
    }
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:52:42+00:00Added an answer on June 1, 2026 at 12:52 pm

    You cannot determine the size of the file selected in the file input element via client side script. In order to determine the size of the file, one must have read access to the file. As you may imagine, allowing JavaScript to read files on your computer would be a “really bad idea.”™

    I often see this type of question, and believe that there is some confusion about what the file input element actually does. When the user selects a file, the file bytes aren’t “loaded” into this element such that they are available for reading. Rather, the input specifies a reference to the file location so that the browser knows – when the form is posted – to encode the file and send it with the POST. This process is internal to the browser, and isn’t exposed to the client in a manner that it can be leveraged by script.

    If you need to do file size verification, you should do it on the server where you have access to the actual file bytes. If you are concerned with people “flooding” your site with very large files, you can specify the maximum allowable POST size by configuring your IIS instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a asp:FileUpload control in my page. The default file size is 4MB.
I have a FileUpload Control and a image control on asp.net page as follows
I have an ASP.NET MVC web page that has a file upload control. Under
I have FileUpload Control on my Page: <asp:FileUpload runat=server ID=fuAttachment CssClass=fileUploadCSS size=76 /> I
I have a web page where i have an ASP.NET file upload control to
Here is my code to post the file. I use asp fileupload control to
I have a file upload control on my page. When a user selects a
I am working on ASP.NET3.5 platform. I have used a file upload control and
I have a Web Application in which I am using asp:FileUpload Control to upload
i have an asp fileupload control, i want to know,,is it possible to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.