Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

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

4.38/5 (8 votes)
17 Dec 2012CPOL2 min read 51.2K   2.8K  
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:

Image 1

C#
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.

Image 2

Image 3

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)