Solved

HTML INPUT tag events

Posted on 2009-05-18
4
877 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

729 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