In my project I need to show a Progress bar in the Page load event.
Basically I get a requiest from another application. Based on the request
My page will create a pdf file. As it will take time to create the pdf file
I need to display a progress bar or an animated gif image as the page is being created.
Any idea how to do it. Remember I am not using any button_click events here.
In my project I need to show a Progress bar in the Page load
Share
I imagine something like this could work:
On document.ready have the gif image displayed by calling a function like this:
with
trueparameter:ShowProgressBar(true);And after the PDF is done being generated; just call something like:
But I have the feeling that it won’t be as simple :S
UPDATE – working example
I figured out a way to make it work but you will need to separate the code that generates the PDF into a different page whose only purpose will be to write the PDF file to the response stream. Better yet, you could write an HttpHandler to write the PDF file to the Response Stream but for the purposes of this example, I’ll write the PDF file from a regular aspx page.
Step 1: Insert the following markup and javascript code in your page.
Explanation: On page load ShowProgressBar is called to start displaying an animated gif image. The following line
-createIframe();-creates aniframedynamically and sets thesrcattribute to be the url of the page that will write the PDF to the Response Stream. It then appends theiframeto the pagebodyand attaches acallbackfunction that will be invoked when theiframeis done loading. Since thecallbackfunction is called whenPageGeneratingPDF.aspxis finished generating the PDF file, the only thing left for thecallbackfunction to do is hide the div containing the animated gif image.The
PageGeneratingPDF.aspxcode behind could look something like this:You are done. The output will be something like this.
Initially…
After generating the PDF…
This other question in StackOverflow, was very helpful.