Click here to Skip to main content
15,917,652 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all,
I am making some functionality in which user waits for the file to get download from the data base. Meantime when the data is mined I want him to see the progress in progress bar. I have seen many examples but they are all on windows application not on websites using c#. Moreover I have done some coding but wht is this INITIALIZE COMPONENT() used with progress bar ?
How can i achieve my task up and running ?
Here is some coding I have done... Kindly look at it and lemme know where I am geting wrong all the way ?
ProgressBar pbar = new ProgressBar();
    BackgroundWorker bw = new BackgroundWorker();
 pbar.Minimum = 0;
        pbar.Maximum = 100;
        bw.DoWork += new DoWorkEventHandler(worker_DoWork);
        bw.ProgressChanged += new   ProgressChangedEventHandler(worker_ProgressChanged);
        
        pbar.Value = pbar.Minimum;
        bw.RunWorkerAsync();

  void worker_DoWork(object sender, DoWorkEventArgs e)
    {
        for (int i = 1000; i >= 0; i--)
        {
            Thread.Sleep(50);
            int percent = (1000 - i) / 10;
            bw.ReportProgress(percent);
        }
    }

    void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        System.Web.UI.WebControls.Label label1 = new System.Web.UI.WebControls.Label();
        pbar.Value = e.ProgressPercentage;
        label1.Text = e.ProgressPercentage + "%";
    }
Posted
Updated 4-Jun-12 2:25am
v2

1 solution

The code you have found is not going to work.

There is a big difference between windows applications and websites. Most important is that a website is client-server based and uses html for communication. The client sends a request to the server and the server sends a response. There is no other communication until another request is sent from the client.

With html only you cannot achieve this, you will need ajax[^] to send asynchronous requests from the client to get the status of the download and update the screen. There are also flash progress bars, but I wouldn't recommend those.

Take a look at this article to get started: http://csharptechies.blogspot.nl/2010/09/displaying-jquery-progressbar-with-ajax.html[^]
 
Share this answer
 
Comments
Taresh Uppal 5-Jun-12 0:35am    
I tried using this but nothing happened ...
Taresh Uppal 5-Jun-12 0:39am    
MOreover what is this
[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)]

it is gving so many errors. I commented them and run the process still no go.
[no name] 5-Jun-12 1:36am    
Did you download the complete source from http://ajaxprogressbar.codeplex.com/SourceControl/list/changesets
I've tried it and the progressbar works.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900