Building AJAX Enabled File Uploading System with Progress Bar Using ASP.NET 2.0
page 4 of 7
by Jesudas Chinnathampi (Das)
Average Rating: 
Views (Total / Last 10 Days): 78836/ 60

Displaying a "Please Wait …" Message during an Upload

To display the "Please Wait … Message" we need to use the UpdateProgress control. The UpdateProgress control that we will be using for our upload will be as follows:

Listing 4

<asp:UpdateProgress ID="UP" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<asp:Label ID="lblWait" runat="server" Text="Please wait.."></asp:Label>

Each time the submit button is clicked the web page will be posted back to the server. You would think that you will see the message, “Please wait.” Well again, we need to look at one more aspect before we can see the “Please wait” message during a file upload.

We need to write a client side JavaScript function that will change the visibility of the UpdateProgress during the post back. The JavaScript will look like:

Listing 5

<script language="javascript" type="text/javascript">
function showWait()
    if ($get('myFile').value.length > 0)
        $get('UpdateProgress1').style.display = 'block';

The function showWait will have to be invoked during the form submission. In our scenario that would be the OnClientClick event for the button control.

Listing 6

<asp:Button ID="btnUpload" runat="server" Text="Upload" 
OnClick="UploadFile" OnClientClick="javascript:showWait();"/>

The complete code listing for both AJAX File Upload and Please Wait message is as follows:

<%@ Page Language="C#" AutoEventWireup="true"%>
<script runat="server">
protected void UploadFile(object src, EventArgs e)
    if (myFile.HasFile)
        string strFileName;
        strFileName = myFile.FileName;
        myFile.PostedFile.SaveAs(Server.MapPath(".") + "//" + strFileName);
<script language="javascript" type="text/javascript">
function showWait()
    if ($get('myFile').value.length > 0)
        $get('UpdateProgress1').style.display = 'block';
    <title>File Upload</title>
<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"/>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <asp:PostBackTrigger ControlID="btnUpload" /> 
            <asp:FileUpload ID="myFile" runat="server" />
            <asp:Label ID="lblMsg" runat="server"></asp:Label>            
            <br />
            <asp:Button ID="btnUpload" runat="server" Text="Upload" 
                OnClick="UploadFile" OnClientClick="javascript:showWait();"/>           
            <asp:UpdateProgress ID="UpdateProgress1" runat="server" 
                    <asp:Label ID="lblWait" runat="server" BackColor="#507CD1" 
                        Font-Bold="True" ForeColor="White" 
                        Text="Please wait ... Uploading file"></asp:Label>

View Entire Article

User Comments

Title: muy bueno   
Name: miguel
Date: 2012-12-17 10:38:32 AM
estado buscando y buscando y todo el mundo ponia que no se podia, jajajaja, asi que estoy muy contento de poder utilizar el fileUplad con updateprogress.
Title: hsds   
Name: sdfg
Date: 2012-12-10 6:17:42 AM
Title: Excellent Article - works perfectly   
Name: Tausif
Date: 2012-11-27 11:10:03 PM
I viewed many sites explaining this but none of those worked. They didnt explain about the javascript code which you have mentioned.
You also took time to explain in detail what every step does. Excellent work!
Title: d   
Name: d
Date: 2012-11-19 4:02:32 AM
Title: test   
Name: Alex
Date: 2012-11-15 5:55:43 AM
Title: SAD   
Name: SAD
Date: 2012-11-04 12:09:55 AM
Title: test   
Name: test
Date: 2012-10-16 2:52:06 AM
ksahjk ksahk
Title: dd   
Name: dd
Date: 2012-09-20 5:56:03 AM
Title: aaa   
Name: aaa
Date: 2012-08-30 3:13:46 AM
Title: Panel containers   
Name: danis
Date: 2012-08-13 7:02:06 PM
Controls in Panels :( dont works

Its works for me.

function showWait() {
if ($get('<%= FileUpload1.ClientID %>').value.length > 0) {
$get('<%= UpdateProgress1.ClientID %>').style.display = 'block';
Title: It is working wonderfully   
Name: yashaswi
Date: 2012-08-10 4:32:42 AM
The concept was working fine .......
Title: vvvvv   
Name: vvvv
Date: 2012-08-06 8:50:05 AM
Title: v   
Name: v
Date: 2012-08-06 8:49:41 AM
Title: sfs   
Name: fsd
Date: 2012-07-25 11:40:12 AM
Title: sad   
Name: asds
Date: 2012-05-28 3:19:15 AM
Title: aa   
Name: aa
Date: 2012-05-19 9:02:29 AM
Title: test   
Name: test
Date: 2012-05-09 12:33:44 AM
Title: need for more help   
Name: Mann
Date: 2011-10-06 8:24:10 AM
I am using ajax enable form and also using some ajax control on the form.still i am unable to upload the file.Can any one have a solution
Title: Delete button   
Name: Maha hamad
Date: 2011-05-22 8:47:54 AM
how i can add Delete button next to the file name that has been updated so the user can delete it
Title: Thank you sooo much   
Name: itsi bitsi
Date: 2011-03-16 3:58:21 PM
Thank you so much. I had been trying to achieve this for 3 days straight. Now I just need upload progress
Title: Thanx for post but its not work   
Name: sebi verma
Date: 2011-02-04 7:25:11 AM
i have applied teh same code and when i am running the page is will some javascript error when i clicked on upload button.

error: "Microsoft JScript runtime error: Object required"

please give some solution for this??
Title: awesome   
Name: shiva
Date: 2010-12-07 4:43:29 PM
this is awesome .. flawless .. great work .. keep it up
Title: Funny Post   
Name: John
Date: 2010-11-05 9:55:51 AM
Dear it is not ajax , it is funny post.. where is progress bar ???
Title: Thanks for the post   
Name: 0988JayLin
Date: 2010-10-11 9:37:10 PM
Nice post ~

But what I need is one with "progress bar" that actually tells the progress of the upload instead of just display "Please wait" label.

Thanks for the sharing.
Title: Thx   
Name: FLOyun
Date: 2010-07-10 9:47:51 PM
Good thx for share.
Name: XIRO
Date: 2010-07-01 12:32:17 PM
Well done brother! What you have done is a solution for the problem of many but I think it is not AJAX.


Why? because of your javascript code, you use it only to show the user about the progress of the upload but not to send file to the server. Also, you've missed one important thing that AJAX is known for, the XMLHttpRequest object.

Hey! don't be offended, Article Feedback is here to help you improve yourself, right?
Title: No Luck   
Name: Prajakta
Date: 2010-05-07 8:14:56 AM
I have tried ur same code in test app. and believ not working at all getting error 'Sys is undefined'
Title: Owesome   
Name: Wee
Date: 2010-03-24 9:37:48 PM
Bro, u'r da man~! and the java script really powerful.
Title: Great Article   
Name: Pebuardi
Date: 2010-03-09 11:16:14 PM
Hi Das,

really a great article, I have try your code in my application, and it running well. Very nice, and simple...
Title: Check the AJAX Library out   
Name: Mr B.
Date: 2010-03-03 3:44:22 PM
Title: Not AJAX!   
Name: Mr B.
Date: 2010-03-03 3:28:28 PM
Worthless as this causes a full page postback.
I wish the comments would come before the article...
Title: Majow flaw with above code   
Name: Michael Freeman
Date: 2010-01-07 8:37:51 AM
I have sucessfully implemented the above code, and all seemed ok, until I realized that it's not AJAX!. Specifillay the code alls a full postback of the page. Ultimately that would not be an issue, but I noticed that other controls on the same parent form lost their contents during this postback, such as all textboxes lost their changes. Upon return from upload (when upload completed) the textboxes contents returned to original, probably due to the fact that the postback triggers Page_load etc events...
Title: Thanks   
Name: Mr. T
Date: 2009-12-22 9:15:07 AM
Brilliant... a very good solution to a very irritating problem. No swf's. No php. Well done.
Title: Thanks   
Name: Koushik
Date: 2009-11-02 6:45:20 AM
Thanks for the solution.
Title: The trriger also not work   
Name: Vivek
Date: 2009-10-22 9:36:11 AM
the uploader has no file when i use file uploader why???
Title: iam no sure   
Name: pedro campos
Date: 2009-10-20 4:01:10 PM
my page do postbak every time i click upload button, why?

and i copy source code idem the example. only the page is ok, but when i insert on my page, that fail, i dont know why.
Title: Building AJAX Enabled File Uploading System with Progress Bar Using ASP.NET 2.0   
Name: Ramya
Date: 2009-09-15 3:02:25 AM
this article is very useful. it's working fine.. Thanks a lot...
Title: Serious?   
Name: LAME
Date: 2009-09-02 12:45:12 AM
This is the farthest thing from an async postback. Does the author even know what the heck an async postback is???
Title: Superb..   
Name: Viji
Date: 2009-08-27 12:38:54 PM
I was breaking my head to do this..
Happy to see this post..
Lemme try this tom... :)
Title: Hmmm   
Name: VIkas
Date: 2009-08-18 3:23:06 PM
So dude, how does it uploads files using Ajax? The upload still causes a full postback. Change the article title..
Title: Good Tutorial   
Name: Chandradev
Date: 2009-08-05 8:18:09 AM
This is very nice tutorial. But while implementing in master page. It is giving so error. And while keeping .gif image inside progress template. It is not rotating. What is the problem ?
Title: Great stuff!   
Name: Stefania
Date: 2009-07-23 4:28:28 AM
Thank you, excellent article.
Title: Appreciate   
Name: Asher Mehboob
Date: 2009-07-06 6:02:37 AM
Thank you for this article. helped alot.
Title: Thank You Thank You   
Name: Chris
Date: 2009-06-19 12:41:10 PM
Thank you for the article. I'm a novice and have been researching this on and off for a week. Everything I found was way overcomplicated for what I need. This is perfect.

Title: Nice   
Name: Jorge Bautista
Date: 2009-06-18 11:19:54 PM
Thank you so much, it was really helpful!
Title: Greate Programming   
Name: amit Kumar Jha
Date: 2009-06-05 7:04:11 AM
I would like to thank a lots to develop such great program in simple way. Really it helped me. I found all thing relted FileUploading in this development.
Title: Very Helpful   
Name: Preeti
Date: 2009-05-21 1:18:56 AM
very helpful........
helped me a lot....
Title: Good article, but..   
Name: Harish Chandra
Date: 2009-05-15 4:10:06 AM
I want progress bar when file uploading take place and progress bar will grow as how much data uploaded (in size).
Title: good article   
Name: Arathy
Date: 2009-05-08 4:46:10 AM

really good article.....thank alot guys..
Title: masterPage-not working   
Name: Tom
Date: 2009-05-06 5:25:20 AM
Hi,good article!!!But did someone find a way to working with Master Page?
Title: count show   
Name: sushil
Date: 2009-04-20 9:06:15 AM
Good article!!! I wonder how can the count can be incremented in progress bar?
Say for example I am uploading an exel file having 100 data, I want to show the count in progress bar like "x data uploaded". Here x will vary from 1 to 100. Thanks!
Title: really helpfull   
Name: ram
Date: 2009-04-10 1:36:16 PM
Very Good Article Thanks
Title: Can't upload to hosted server   
Name: Larry
Date: 2009-03-29 6:38:22 PM
I can't understand how this could work since it just saves the file to the server. If you're on a hosted server then there's no way you can load a file to it. What I want is to be able to save the file in the database on the server. However, all attempts have failed with a "Request for the permission of type 'System.Security.Permissions.FileIOPermission" error.

By the way, you can't do a file upload without a full postback according to the literature out there, so that's not why you use the updatepanel. You use it for other aspects of the file upload process.
Title: Display message does not show   
Name: joar
Date: 2009-03-11 5:04:45 AM
I was happy to see your solution, but as often happens, solutions doesn't always function....for me
Title: Not working   
Name: mab
Date: 2009-02-27 9:26:28 AM
hi... this is good job! but this code not working with master page!!!
Title: My 'please wait' doesnt show   
Name: Pinch
Date: 2009-02-18 4:41:12 PM
My 'please wait' doesnt show, but it does upload, any ideas? thanks,
Title: So   
Name: chawelson
Date: 2009-02-12 4:03:25 AM
Lemmie try this out
Title: Hmmm   
Name: Danieö
Date: 2009-01-13 9:36:05 AM
What's the the purpose of using an updatepanel here? You're still doing a full postpack, so why not use a div to show/hide the label?
Title: Good!! It worked for me   
Name: Mukesh
Date: 2008-11-24 11:32:12 AM
Hi! It worked for me..Thanks a lot..
Title: Problem with code   
Name: Preeti
Date: 2008-10-14 2:07:34 AM
this code is good but it doesn't work for large size files
Title: Building AJAX Enabled File Uploading System with Progress Bar Using ASP.NET 2.0   
Name: deva
Date: 2008-09-16 10:24:33 AM
update progress is not working and first time not upload to server, second time we upload any file, then only upload that file.
This code not working in VS2005.
Title: hi   
Name: bahador
Date: 2008-09-11 7:21:21 AM
hi freid
thanks alot fot your article
Title: very nice   
Name: mehmet
Date: 2008-09-10 4:54:18 AM
very very thanks...
very good work
Title: Building AJAX Enabled File Uploading System with Progress Bar Using ASP.NET 2.0   
Name: Neeraj k Shrivastwa
Date: 2008-08-06 6:34:51 AM
The FileUpload Server Control does not work within the UpdatePanel. Within the updatepanel the HasFile property of FileUpload control always comes false.
Title: Super   
Name: MMK
Date: 2008-08-05 5:59:43 AM
Title: No Progress Bar   
Name: Nic
Date: 2008-07-23 8:12:42 AM
There is no progress bar here so the title is even more misleading...
Title: Feedback   
Name: Meera
Date: 2008-07-01 2:41:11 AM
Can this be done in a user control???
Title: hi   
Name: jeni
Date: 2008-06-09 4:10:17 AM
its helpfull
Title: Good Code   
Name: Naresh
Date: 2008-06-05 9:49:13 PM
Very clear saving me from lot of confusion...
Title: PostBackTrigger ???   
Name: AL
Date: 2008-05-16 7:11:44 AM
What reason put this in UpdatePanel if you use PostBackTrigger? This is full PostBack!
Title: Good Code   
Name: Rahi
Date: 2008-05-14 4:56:31 PM
Saved me a lot of time...
Title: Have to agree with the new guy   
Name: Blake Shadle
Date: 2008-04-10 9:18:53 AM
I'm going to have to agree with the new guy on this one. Not exactly the "AJAX" experience that I'm sure everyone hoped for.
Title: error when in UserControl   
Name: Exshakto
Date: 2008-04-03 6:03:27 AM
Im trying to put this in a User Control, and im getting an error in the javascript. Where do you think I should put the javascript when its in a user control?
Title: cool   
Name: Sudhir T
Date: 2008-03-10 8:07:34 AM
Nice post. Simple and beautiful
Title: great!!!!!!!!   
Name: sadhana singh
Date: 2008-02-27 9:58:15 PM
very nice please keep on pasting more materials it helped me lot thx again!!!!!!!!!
Title: Postback is happening   
Name: Nagaraj
Date: 2008-02-01 5:41:17 AM
Still postback is happening when we upload file.
Title: The title is misleading!!!   
Name: MCM
Date: 2008-01-18 3:10:43 PM
This is NOT AJAX. It just doing a full post back. If it's just post back without utilizing any AJAX...why would you need to put it into an update panel?
Title: Very Good Ariticle   
Name: Rahul Chauhan
Date: 2008-01-07 1:52:32 AM
Plz keep on posting new tutorials on ajax.

Great Job
Title: Good   
Name: Rajak Shaik
Date: 2007-12-14 12:06:31 AM
Very good article
Title: How to upload the media   
Name: Cristiano
Date: 2007-12-12 8:37:19 AM
How to upload some media like mp3 songs and picture .jpeg
Title: Need attachment in Sharepoint Designer Form   
Name: Kuldeep Singh
Date: 2007-12-10 6:27:55 AM
Would you please explain how can i use this code in my Sharepoint Designer custom form????
Title: .NET Programmer   
Name: Raj
Date: 2007-12-03 12:13:15 PM
Awesome buddy, although simple it made my day today. Superb.
Title: Misleading Title   
Name: Haissam Abdul Malak
Date: 2007-11-30 2:11:36 AM
The article is explained in a good way, however the content is not related to the title!!
Title: hail to the n00bz   
Name: Michael
Date: 2007-11-15 8:00:39 AM
Great article, thanks ;)
:) Although I'm using this for my current project:
The price is pretty steep though but it has yummy resize and thumbnailing along with other stuff that I don't need :)
Title: one more developer   
Name: Dotnet Coder
Date: 2007-11-14 4:46:45 PM
Even though you are using UpdatePanel. It is not actually AJAX, it is posting synchronously all the time.
Title: How to change postedFile?   
Name: nice
Date: 2007-11-13 8:33:45 PM
How to change (in code) myFile.PostedFile in UploadFile() method? Changing it u can steal any file form client hard drive :-)
Title: URL   
Name: JasonJ
Date: 2007-11-13 11:56:48 AM
Here is the link.
Title: Cheating   
Name: JasonJ
Date: 2007-11-13 11:55:45 AM
This method simply fakes an ajax postback and which might look cool but defeats the whole purpose of the ajax postback. Anyway, here is a link to a page that does it correctly, using an IFrame as Microsoft does in Hotmail.
Title: FileUpload AJAX   
Name: Subgurim
Date: 2007-11-13 5:32:20 AM
Great, but take a look at the FileUpload AJAX control for ASP.NET hosted on codeplex (
Title: Update Panel not working in side from view   
Name: QuocThinh
Date: 2007-10-08 2:58:54 AM
Hi all, I just try your method, but I have a form view all the field will be save to the database, among that, I have fileUrl file that contains the uploads filename, so I must put this upload file inside the form view. But it not working both update panel and update progress, I don't know why.
Title: Not working with gif IE7 solved   
Name: lp
Date: 2007-10-04 10:46:25 AM
Sorry for the 3rd comment ;-) but I've found solution for IE7 here

add this to JavaScript:
setTimeout('document.images["Progressbar"].src = "progressbar_green.gif"', 200);

and set ID of the image to "Progressbar".
Title: Not working with gif   
Name: lp
Date: 2007-10-04 10:01:27 AM
In FF it's working, IE7 and Opera not :-(
Title: Not working with gif   
Name: lp
Date: 2007-10-04 9:47:28 AM
Thx for the article.

But I got a problem. Text (Label) is working OK but using gif e.g. from doesn't work - it shows only a white place. Any idea?
Title: This is NOT a AJAX based File Upload Method   
Name: Adam Nemitoff
Date: 2007-10-03 10:32:54 AM
The method documented here does a full post-back and therefore the title of this article is misleading!
Title: why?   
Name: Mikal Schacht Jensen
Date: 2007-10-03 3:46:46 AM
I've been attempting to upload files using ASP.NET ajax, and although I haven't spent much time exploring it, I always ended up having to do a full postback to actually be able to retrieve the file serverside. So when I first saw this article linked somewhere, I immediatly clicked over here.

I'm still a fairly inexperienced programmer with less than a year's paid programming under my belt. But having read it now, I fail to see the point of it all. Doesn't adding the button to a postbacktrigger make it cause a full postback, and thus defeat the entire purpose of using Ajax?
Title: Rc   
Name: rahul
Date: 2007-10-03 2:33:35 AM
good, but not explored ajax much

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-07-23 1:45:48 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search