Link to home
Start Free TrialLog in
Avatar of rivkamak
rivkamakFlag for United States of America

asked on

asp.net not stopping image upload size.

I have a  simple asp.net form that is uploading an image.
Even though I put the max-file-size in my form, it's not stopping the page from working and the user just gets an error.
how can I stop the script from erroring and ask the user to retry their.
I am using asp.net 2.0
Thank you

  <form id="form1" runat="server">
            <div>
              <asp:FileUpload ID="FileUpload1" name="FileUPload1" runat="server" />
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                    ControlToValidate="FileUpload1" ErrorMessage="File is required"></asp:RequiredFieldValidator>
              <br /><input type="hidden" name="MAX_FILE_SIZE" value="100000" />
              <br />
              <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" 
         Text="Upload File" />          
              &nbsp;<br />
              <br />
              <asp:HiddenField ID="id2" runat="server"   />
              <asp:Label ID="Label1" runat="server"></asp:Label>
            </div>
      </form>

Open in new window

Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

You cannot check the size of the file before it is uploaded to the server. You can only upload to the server if the file is less that the size allowed on server. You would need to use Javascript or other client side technique to achieve this.
Avatar of rivkamak

ASKER

how can i do this with javascript?
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial