Solved

HTML INPUT tag events

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
daypilot scheduler 3 26
Easy responsive table out of existing table 28 55
Html5 string 3 20
How do I pull the base url for use in html links 7 22
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…
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 transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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…

786 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