Progressive Load on an ASP / SQL Query?

I've got an ASP (VBScript) page that I'm doing a SQL query on, and it takes a while to complete retrieving/displaying all the records, so I'd like for the first part of the page to load, and then show the query results after they come in.  I've seen this done on ASP pages before.  How would I do this?

Thanks in advance!
mediapandererAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tomvergoteCommented:
It's done using the response.buffer and response.flush methods.
if you set response.buffer on the first line of your script, you can then call response.flush to send what's already in the response stream to the browser:

<%
response.buffer=true
response.write "some quick stuff"
response.flush
response.write SomeSlowMethod()
response.flush
response.end
%>

You do have to be a bit careful about not flushing things like half a table or something to the client because things like that will render in a weird way
eg:
response.write "<table><tr><td>quick stuff"
response.flush

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
UnblondeAlCommented:
Just to add to this. Tables generally render all at once, so if you want to render progressively, you need to split the table up. A good way to that is to include a counter in the code that you use to create the table rows, and then close the table and create a new one everytime it reaches a certain number.

The response.flush code is only necessary if you are using response.buffer - if you are not, which is the default, you can remove the flush line from the code below. You can tell if you are, by write clicking on teh page and clicking view source as it is loading. If you can see half a table in there, then it it not being buffered.

Heres an example in Pseudo Code

dim x = 1
response.write "<table>"
for each Record in recordset
    if x mod 20 = 0 then      'every 20 records (in JScript this is if(x % 20)   )
         reponse.write "</table>"
         response.flush
         response.write "<table>"
    end if
     Response.Write "<tr><td>" + record("Name") + etc + "</td></tr>"
     x = x + 1
end for
response.write "<table>"

Finally, the only disadvantage of this, is that you need to size all the cells of your table to make sure they line up (either using percent or pixel widths). If you leave the cells to size themselves, they may be different widths depending on the content in each individual table.

Any questions, please ask

Alex
UnblondeAlCommented:
I should add, when i say tables usually render all at once, i mean in the browser. tomvergote is addressing a possible problem with the data being slow in getting from the server to your computer. I'm addressing a possible problem with your browser waiting until it has all the data until it draws the table. Which the correct solution is depends on your problem (though i believe that firefox displays tables before it recieves all the information, so if your page renders faster in their, then my solution would be the way to go for sure.)

Alex
mediapandererAuthor Commented:
I love it!!  Thanks a bunch!  Alex thanks a lot for your trick too...I'm not running into this now but will keep it in my bag of tricks.

Thanks again!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.