views:

909

answers:

4

Hi,

is there any chance to show a loading bar while creating something in a loop with classic asp?

I thought about some ajax-style loading bar which shows that the page is stil creating something.

I tried to do it with session variables which contains status information of the process but on this i found out that asp servers have a queue which means you can run only one asp-page at the same time.

While loading the asp-page i cant open another asp-page on the sam server with the same session. With a new Session is this possible but i want to work with the same session ( if this is possible ).

Thoughts: Can it be done with a ajax request which requests the asp-page and shows a loading bar while the page is loading?

Is there any workaround to work a status bar out?

(sorry for bad english) Thank you

Edit:

I this way but i can't access the session variable over a asp-page. The session reader page gives me only a answer after the first asp-request is done. I think this is a session-queue-think.

it looks like this for me:

ajax page --(request process asp page)-> process.asp

(same ajax page) --(request session reader page)-> sessionreader.asp

while sessionstatus != 100 show process bar

the problem is i got a answer from sessionreader.asp when the process.asp is done. That is why i think this is a asp-session-queue-think.

Maybe it will work if a give the second request a new Session id (if this is possible at all) ?

+1  A: 

You can trigger a GIF animation on the client side, the moment you dispatch a request.

EFraim
That wouldn't show a real time progress bar.
Andrew Siemer
That's right. But most of progress bars are not real time. They are mostly indications of "action in progress, be patient." Though there are some exceptions such as file upload in GMail, which is based on Flash IMHO.
EFraim
+1 A reasonable pragmatic solution.
AnthonyWJones
A: 

You won't be able to do this with just one asp page. You will need a page that is shown to the user (where you progress bar lives). Then you will need to make an ajax call (with jQuery??) in a loop to a page that reads a session object. And you will need a page that is actually doing your processing and writing it's status to the session that is being periodically monitored by the ajax call. You will need to make periodic calls with the ajax to check the session over time until you reach the final result. You could store a number in the session say 1-100 if it is a really long slow process...but 10, 20, ..., 100 would probably work best. When you get to 100 you would break the loop and no longer poll the session reading page.

The reason for this is that you need a page to display to the user for your bar.

The page that is doing the processing can't show anything to the user until it is done processing.

The page that simply reads the session can process quickly and show its results quickly.

Make sense?

Andrew Siemer
+1  A: 

There used to be a trick with either disabling the Response.Buffer (set it to false) or let it be buffered, but from time to time you do Response.Flush as you want to update your progress.

So, say you have your progress bar somewhere on top portion of your page (either image or table or div or whatever you want) and as you do something in asp script (say in a loop), from time to time, flush a javascript back to the client to update the progress bar that should already be on the screen. something like:

<%
  REM Might be a good idea to set the timeout to some large number here...
  Response.Timeout = ...
%>
<html>
:
<body>
  <p>Please wait...<span id="progress">0</span>% completed.</p>
  : content here...
  <%
  REM Make sure the things above this get sent to the client first
  REM so they will be rendered before the rest of the page is rendered.
  Response.Flush()

  For iCnt = 0 To 100
    REM Do some stuffs here...

  %>
    <script>$("#progress").html(i)</script>
  <%
    Response.Flush()
  Next
  %>
  : some more contents here...
</body>
</html>

I'm not sure if this still works with modern browsers, haven't use it in a while.

Jimmy Chandra
Yikes! I haven't seen a REM statement in years. ;)
AnthonyWJones
LOL, I haven't been in vb / vbscript world since .NET :) even during ASP day I prefer to write my server script using jscript instead near the end :).
Jimmy Chandra
i tried this out and it worked for me fine i will try to write it in jscript ( i think this wont be a problem ) and then to merge it with my asp code.Thank you
OemerA
A: 

You are on the right track that the problem is that you are developing on Windows XP and running into the limitation that IIS 5 will only process one request at a time.
As you suspect the AJAX request for the progress is not returning until the original request that you are trying to monitor is finished.

There is no way around this that I know of with this version of IIS. It is likely another limitation built in to prevent you from using XP IIS 5 in a production environment. Even if a second request is coming from another machine with a different ip address it will not be processed until the first is complete.

pflunk
Thank you i think you are right but i tried to do open the process.asp in firefox and the sessionreader.asp in IE in it works fine.In my desperation i wrote the status in a file and read it with the sessionreader.asp ( i know its a horrible workaround ) It works but if want to open both files (process.asp and sessionreader.asp) i get an answer from sessionreader.asp when process.asp is done.Thats why i think its Session based queue.
OemerA