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 6694853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:09:02+00:00 2026-05-26T06:09:02+00:00

I am using ASP.NET C# 4.0, my web form consist of input type file

  • 0

I am using ASP.NET C# 4.0, my web form consist of input type file to upload images.

i need to validate the image on client side, before saving it to my SQL database

since i am using input type= file to upload images, i do not want to post back the page for validating the image size, dimensions.

Needs your assistance
Thanks

  • 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-05-26T06:09:03+00:00Added an answer on May 26, 2026 at 6:09 am

    you can do something like this…

    You can do this on browsers that support the new File API from the W3C, using the readAsDataURL function on the FileReader interface and assigning the data URL to the src of an img (after which you can read the height and width of the image). Currently Firefox 3.6 supports the File API, and I think Chrome and Safari either already do or are about to.

    So your logic during the transitional phase would be something like this:

    1. Detect whether the browser supports the File API (which is easy: if (typeof window.FileReader === 'function')).

    2. If it does, great, read the data locally and insert it in an image to find the dimensions.

    3. If not, upload the file to the server (probably submitting the form from an iframe to avoid leaving the page), and then poll the server asking how big the image is (or just asking for the uploaded image, if you prefer).

    Edit I’ve been meaning to work up an example of the File API for some time; here’s one:

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
    <title>Show Image Dimensions Locally</title>
    <style type='text/css'>
    body {
        font-family: sans-serif;
    }
    </style>
    <script type='text/javascript'>
    
        function loadImage() {
            var input, file, fr, img;
    
            if (typeof window.FileReader !== 'function') {
                write("The file API isn't supported on this browser yet.");
                return;
            }
    
            input = document.getElementById('imgfile');
            if (!input) {
                write("Um, couldn't find the imgfile element.");
            }
            else if (!input.files) {
                write("This browser doesn't seem to support the `files` property of file inputs.");
            }
            else if (!input.files[0]) {
                write("Please select a file before clicking 'Load'");
            }
            else {
                file = input.files[0];
                fr = new FileReader();
                fr.onload = createImage;
                fr.readAsDataURL(file);
            }
    
            function createImage() {
                img = document.createElement('img');
                img.onload = imageLoaded;
                img.style.display = 'none'; // If you don't want it showing
                img.src = fr.result;
                document.body.appendChild(img);
            }
    
            function imageLoaded() {
                write(img.width + "x" + img.height);
                // This next bit removes the image, which is obviously optional -- perhaps you want
                // to do something with it!
                img.parentNode.removeChild(img);
                img = undefined;
            }
    
            function write(msg) {
                var p = document.createElement('p');
                p.innerHTML = msg;
                document.body.appendChild(p);
            }
        }
    
    </script>
    </head>
    <body>
    <form action='#' onsubmit="return false;">
    <input type='file' id='imgfile'>
    <input type='button' id='btnLoad' value='Load' onclick='loadImage();'>
    </form>
    </body>
    </html>
    

    Works great on Firefox 3.6. I avoided using any library there, so apologies for the attribute (DOM0) style event handlers and such.

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

Sidebar

Related Questions

How can I get an ASP.net web form (v3.5) to post a file using
I'm using ASP.NET Web Pages to create a form in which I can select
I am using ASP.NET 4.0 membership api in web form application. I want to
I'm writing a pretty complex web form using ASP.NET Dynamic Data. Several of the
I have a simple form with some plain html input like bellow using ASP.NET
Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators? For
I'm writing an ASP.NET 3.5 web application. There is a rather complex input form
I am using JQuery mobile in asp.net web form website. I have the following
I need to push something into my ASP.NET web form page from a Silverlight
i'm using asp.net web form fx3.5 and i'm trying to get my server-side string

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.