Click here to Skip to main content
Click here to Skip to main content
Go to top

Showing File Upload Progress to the user using UpdatePanel control in ASP.NET

, 17 Dec 2012
Rate this:
Please Sign up or sign in to vote.
This article describes the working of fileupload inside an updatepanel and showing the file upload progress to the user.

Introduction  

This article describes the working of FileUpload inside an UpdatePanel and showing the file UploadProgress to the user.

Background

AJAX is a playing an important role in ASP.NET developers world, in terms of user experience and responsiveness. There are many scenarios when we have to use FileUpload in a page which have no postbacks. This article describes the working of FileUpload inside an UpdatePanel with UpdateProgress.

The problem is that the FileUpload control does not work with asynchronous postbacks, and therefore does not work from within an AJAX UpdatePanel. This article allows the FileUpload control to work within an UpdatePanel. The example will be a simple web page containing a FileUpload, Image control, Updatepanel, Updateprogress, and a button. We will see that the FileUpload will function inside an UpdatePanel with UpdateProgress.

Using the code

So as per our requirements, we are trying to user file upload control to perform a full postback, and we do this using triggers. Triggers allow the developer to specify what will cause partial and full postbacks. They must be defined within the UpdatePanel but outside of the ContentTemplate. We want to create a trigger that will instruct the button that we are using for the upload to perform a full postback. The updated markup is:

protected void Button1_Click(object sender, EventArgs e)
{
    System.Threading.Thread.Sleep(2000);
    Label1.Text = "Data Processed Successfully";

}
protected void Upload_Click(object sender, EventArgs e)
{
    if (FU1.HasFile)
    {
        FU1.SaveAs(MapPath("~/Image/" + FU1.FileName));
        System.Drawing.Image img1 = System.Drawing.Image.FromFile(
                         MapPath("~/image/") + FU1.FileName);
        ImageView.ImageUrl = "~/Image/" + FU1.FileName;
    }
}

Now when we click on upload button, The uploaded image will be viewed without having asynchronous postback. After clicking on final submission UpdateProgress will get active and show an processing image and the data get ready for the finalization.

Point of interest 

In this article we saw how we can put a FileUpload control inside an UpdatePanel to provide the feedback to the user that the file is being uploaded. This is fairly known to a lot of developers but people new to development will find it useful.

History

11 October 2012: First version. 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

AshishChaudha
Software Developer
India India
I am a Software Engineer from Bhopal. I started my Career from Programming in ASP and now working as a Web Developer in ASP.Net (C#). I Love coding and always ready to gain new thing and always been towards Microsoft Technologies. Apart from coding my other hobbies are traveling, Internet Surfing, spending time with family and hang out with friends.
 
http://www.webtekspace.blogspot.in/
Follow on   Twitter   Google+

Comments and Discussions

 
QuestionMessage Removed PinmemberMember 382310126-Oct-12 21:23 
AnswerRe: nice one very nice PinmemberAshishChaudha16-Dec-12 22:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140921.1 | Last Updated 17 Dec 2012
Article Copyright 2012 by AshishChaudha
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid