0

My problem is I have a method which loading some datas. It took about 10-15 second until the website is loaded. I wanna add a progress bar to the site for the user to show him how long it takes to complete loading the website.

I made a progress bar with pace.js and added it to the .html. The problem is I need something in my controller because the html will start after my method is finished. At the moment I start my website the datas loading and after that my progress bar appears for a second. Could I add my script to a button or is there another solution?

Thanks

Mister
  • 25
  • 6
  • 1
    Share your code please – Alexis Oct 12 '16 at 07:20
  • I can't... But the code isn't important. I have some Ping tests... and while the program check this test, I wanna have a progress bar on my website. My question is now, how can I develope a progress bar in my C# code? Is this possible? – Mister Oct 12 '16 at 07:36
  • how about calling your JS function in your method? like [here](http://stackoverflow.com/questions/5731224/calling-javascript-function-from-codebehind) – Badiparmagi Oct 12 '16 at 08:43
  • Is it possible to start my C# method from my cshtml file? – Mister Oct 12 '16 at 10:03

1 Answers1

1

The progress bar initializes after the load happened. In fact, the load happens on the server before aything is sent to the browser. I would solve the problem as follows:

  1. I would modify my code to make sure that the slow part of the code does not execute on the server before it responds to the browser and the slow part can be reached via POST requests.

  2. I would have a loaded event in the browser, where I would initialize the progress bar.

  3. After the progress bar is initialized, I would send a separate AJAX code for each subtask of the slow task (yes, I would partition the slow task if possible).

  4. These async AJAX requests would have a callback which would refresh the progress bar's status according to the current situation. The last callback would close the door (finish the progress bar's life-cycle).

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175