Solved

HTML INPUT tag events

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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
Help with mod_substitute 18 42
Validating Date Part2 2 27
locate sql commands in C# visual studio Project 6 44
Text color and background in a text box. 2 25
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

733 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