Pages

Wednesday, 27 June 2012

Showing update progress with file upload control in asp.net


Most of us use file upload control in our applications. The problem with the file upload control is you cannot use it inside update panel. And as a consequence you cannot show update progress while the file is being uploaded. Below is the workaround solution for this problem.

1) Add a Scriptmanager and a timer to the page.

2) Set the Enabled flag of the timer to FALSE.

3) In the Page_Init event of the page, add a isCalled key with value as "yes" to the ViewState like this
    ViewState["isCalled"] = "Yes";

4) On the click event of the Upload button (or the button which will start the upload of your file), do these steps
 (i) Set the viewState isCalled Value as "no":

     ViewState[
"isCalled"] = "No";


 (ii) Make your Waiting panel/image visible.Make sure the panel is inside an update panel :

       this.pnlWait.Visible = true;

 (iii) Enable your timer.

            Timer1.Enabled = true;

5) Now your timer is enabled and it will start ticking. So create the timer_tick event for your timer and write the following code in it.

   Timer1.Enabled = false;// disable the timer so that it is not called again 
    if (ViewState["isCalled"].ToString() == "No")
   {
     this.pnlWait.Visible = false
; // hide your loading panel
      ViewState["isCalled"] = "Yes"     
     StartUpload();
//start your upload process

     }



And you are done. Let me know if you find any issues in it

No comments:

Post a Comment