?
Solved

HTML INPUT tag events

Posted on 2009-05-18
4
Medium Priority
?
878 Views
Last Modified: 2012-05-07
I am using the HTML INPUT tag on a website (type="File") to allow the users to upload files.   It looks like the default max file size is 4MB.   If the file is larger than that, it just clears the input control and does nothing everytime there is a postback.   Is there an event that fires off or some way that I can display a message to the end user letting them know that the file was too large?
0
Comment
Question by:amb1313
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:Krummelz
ID: 24412803
You will need to create the uploader as follows:

<input ID="File" Type="File" RunAt="Server" causesvalidation="False" />

make sure the runat="server" is added so that you can work with it from the code.

then you can use the File.PostedFile.ContentLength to check if their file has exceeded the required size. ContentLength is the size in bytes.
0
 

Author Comment

by:amb1313
ID: 24413323
Does it matter that this is a 1.1 .NET application?   I tried adding the causesvalidation="False" to my control but it didn't seem to do anything.

Below is a snippet of what I am using.   The upload button is where I want to have all my validation take place.   If the file is over 4MB, when I click on the Upload button, the event never fires off.  Instead the page refreshes and the value for the input control is lost.   I know I can use a config setting to increase that 4MB limit but I don't really want to do that.   I want to enforce that limitation in addition to letting them know that a file size was too big if it's greater than that.


<input id="txtNewDocument" type="file" name="txtNewDocument" runat="server" onkeydown="return false;" causesvalidation="False">
 
<asp:button id="btnUploadDocument" Runat="server" Text="Upload Document"></asp:button>

Open in new window

0
 

Accepted Solution

by:
amb1313 earned 0 total points
ID: 24416369
Well I ended up finding  aolutiion to this.   I don't really think this is ideal but it will work for what I need.

What I did was add the line of code below to my web.config to allow file sizes of 10MB instead of the default of 4MB.   This allows my code-behind to fire off and then I'll do the check in there by looking at the PostedFile.ContentLength to see how large it is.   If it's more than 4MB, I'll display a message to the user and prevent the upload.

<httpRuntime maxRequestLength="10240" />
0
 
LVL 5

Expert Comment

by:Krummelz
ID: 24418905
Ok, thats what I did aswell -  just show them a message after posting back. If it was .NET 3.5 you could probably use it in an update panel and not lose the value in the upload box. Or save it in viewstate on postback, and restore the value from viewstate if the check fails. But then, if the file is too large, then you would probably expect the value to be lost, because the user will have to choose another file anyway.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question