Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display message during page processing 1

Status
Not open for further replies.

NickBulka

Programmer
Aug 10, 1999
832
US
I have a few pages that do quite a bit of processing, and because of this, it takes a while to display the results. I'm looking for a good way to display a message that the page is processing, and then replace it with the actual page contents when they're ready. Anybody have any good techniques for doing this?
 
In that case I would just buffer(Response.Buffer = True) the page, at the top output "Processing, thend
Response.flush right after that, and it'll flush out everything before, then continue with the processing, and when its done do another Response.Flush to finish it off, Response.end to end the page.
 
Thanks for the input, guys. The response.buffer trick is something I thought of right off the bat, but the subsequent response.writes just get added to the page, so the "please wait" never goes away, even after the page is loaded.

The article referenced by Jeff has an interesting solution, but it causes a maintenance nightmare, since it creates files dynamically that need to be deleted or the disk will fill up rather quickly.

My predicament is compounded by the fact that I'm working inside a frameset, and I can't write anything to the top frame. My content shows in the bottom frame.

Any other suggestions?

thanks.
 
Dear Nick,

The article that Jeff pointed you to does provide a simple "Please Wait" solution that is not 'added to' after the page is finished. Is that still off the mark of what you are looking for? Please clarify.

-pete
 
Pete,
Unfortunately, that solution creates other problems dealing with hitting the refresh/back/forward buttons, and other frame-related nightmares.
Also, I've found the following statement not to be true:
"the original page would stay on screen in the browser until the first bytes of the new page are sent."
my experience is that the page disappears as soon as the form is submitted, resulting in a blank frame while the processing is going on. This is the exact problem that I'm trying to solve.


 
Dear Nick,

This works in IE5. I'm not real sure that it fits all your criteria like frames or even your server side processing but maybe you can change it to do something that will help you out.

-pete

<style type='text/css'>
<!--
#progMsg{
position: relative;
display: block;
}
#progbar{
width: 10;
border: 1 solid #333333;
background-color: #3333cc;
}
//-->
</style>
<script language=javascript runat=server>
function wait(nSecs){

var dtStart = new Date();
var dtNow = new Date();
while ( (dtNow.getSeconds() - dtStart.getSeconds()) < nSecs)
dtNow = new Date();
}
</script>

</head>
<body>
<div id=&quot;progMsg&quot;>
Processing...
<div id=&quot;progbar&quot; >
</div></div>

<%

for(i=20; i<70; i += 10){
wait(2);
Response.Write(&quot;<script language=javascript>document.all('progbar').style.width &quot;);
Response.Write(&quot;= &quot; + i + &quot;; </script>&quot;);
}

%>
</BODY>
</HTML>
<script language=javascript>
document.all(&quot;progMsg&quot;).style.display = &quot;none&quot;;
</script>
 
Thanks, Pete. I tried including your code into a page, but couldn't get it to do anything. In any case, I don't really care if I have a progress bar. All I really need is a static text message that will display, and get replaced with the real contents, without the headache of cleaning up temp files.

If I didn't have to deal with frames, it wouldn't be so bad.
 
Heres an idea. I just threw this code together but heres the gist of it...
1. Display the wait message
2. Write the html of the table you are building to a file on disk
3. When the page is finished processing, redirect the user to the html page on disk.

<%@ Language=VBScript %>
<% Option Explicit %>

<%
'make sure buffering is OFF!
Response.Buffer = False
Response.Expires = 0

Response.Write &quot;<h3>Please wait</h3>&quot;


'simulate some processing
Dim i
For i = 0 To 100000
[tab]i = i + 1
Next

'Build a path to the current folder
'users accessing the machine must have NT Write access to this folder
'so you might want to think about putting this is a separate &quot;safe&quot; folder
Dim sFilePath
sFilePath = Server.MapPath (&quot;.&quot;) & &quot;\table.htm&quot;

'build the table
BuildTable sFilePath

'use javascript to redirect... tried using server.transfer and response.redirect
'neither did exactly what i wanted
Response.Write &quot;<script type='text/javascript'>&quot;
Response.Write &quot;document.location.href='table.htm';&quot;
Response.Write &quot;</script>&quot;

'if you are concerned about leaving the file on disk, you could write a delete routine
'shouldn't be an issue cuz the CreateTextFile method will overwrite the file


'INPUT: Physical path to a file
'OUTPUT: a text file with the HTML representing a table
Sub BuildTable (sFilePath)

[tab]Dim Rs, sql, dsn
[tab]Set Rs = Server.CreateObject (&quot;ADODB.Recordset&quot;)
[tab]sql = &quot;SELECT * FROM Orders ORDER BY OrderId&quot;
[tab]dsn = &quot;Provider=SQLOLEDB; Data_Source=(local); Initial Catalog=Northwind; User Id=sa; Password=;&quot;

[tab]
[tab]Dim fso
[tab]Set fso = Server.CreateObject (&quot;Scripting.FileSystemObject&quot;)
[tab]Dim fTextFile
[tab]Set fTextFile = fso.CreateTextFile (sFilePath, True)

[tab]Dim htm
[tab]
[tab]Rs.Open sql, dsn

[tab]Dim iNumFields, iFld

[tab]fTextFile.WriteLine &quot;<TABLE Border=1 Width='100%'>&quot;

[tab]iNumFields = Rs.Fields.Count
[tab]'Write all the field names
[tab]'as column headings
[tab]fTextFile.WriteLine &quot;<TR>&quot;
[tab]For iFld = 0 To iNumFields - 1
[tab][tab]fTextFile.WriteLine &quot;<TD>&quot; & Rs.Fields(iFld).Name & &quot;</TD>&quot;
[tab]Next
[tab]fTextFile.WriteLine &quot;<TR>&quot;


[tab]'Write the cell values
[tab]Do While Not Rs.EOF
[tab][tab]fTextFile.WriteLine &quot;<TR>&quot;
[tab][tab]For iFld = 0 To iNumFields - 1
[tab][tab][tab]fTextFile.WriteLine &quot;<TD>&quot; & Rs.Fields(iFld).Value & &quot;</TD>&quot;
[tab][tab]Next
[tab][tab]fTextFile.WriteLine &quot;</TR>&quot;
[tab][tab]Rs.MoveNext
[tab]Loop

[tab]fTextFile.WriteLine &quot;</TABLE>&quot;
[tab]Rs.Close
[tab]Set Rs = Nothing

[tab]fTextFile.Close
[tab]Set fTextFile = Nothing
[tab]Set fso = Nothing
End Sub

%>
 
Nick,

Sorry you had trouble with the last code post. Here is an entire page that runs in IE from Win2000 IIS 5 server.

This should provide an easy solution for you to work with even in frames. If you need to talk about the frames managment I am more than happy to work with you on it.

-pete
<%@ language=javascript %>
<% Response.buffer = false %>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Developer Studio&quot;>
<META HTTP-EQUIV=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<TITLE>Long working page</TITLE>
<style type='text/css'>
<!--
#waitMsg{
position: relative;
display: block;
}
#content{
position: relative;
display: none;
}
//-->
</style>
<script language=javascript runat=server>
function wait(nSecs){

var dtStart = new Date();
var dtNow = new Date();
while ( (dtNow.getSeconds() - dtStart.getSeconds()) < nSecs)
dtNow = new Date();
}
</script>

</head>
<body>
<div id=&quot;waitMsg&quot;>
Processing...</div>
<div id=&quot;content&quot; >
<table border=1>
<%

for(row=0; row<5; row++){
wait(1);
Response.Write(&quot;<tr>&quot;);
for( col=0; col<10; col++){
Response.Write(&quot;<td>&quot; + row + &quot;, &quot; + col + &quot;</td>\r\n&quot;);
}
Response.Write(&quot;</tr>\r\n&quot;);
}
%>
</table>
</div>

</BODY>
</HTML>
<script language=javascript>
document.all(&quot;waitMsg&quot;).style.display = &quot;none&quot;;
document.all(&quot;content&quot;).style.display = &quot;block&quot;;
</script>
 
Nick!

An awful error in my wait() code. It was probably the reason the first code failed to work for you as well.

This will actually work:

function wait(nSecs){

var dtStart = new Date();
var dtNow = new Date();
while ( (dtNow.getTime() - dtStart.getTime()) < (nSecs * 1000))
dtNow = new Date();
}


I apologize for the poor code
-pete
 
Pete,
Not sure why, but the code still doesn't work. All I get is a table displayed. (IE5.5)

Jeff,
The method you're suggesting is essentially what the article suggests. However, I'd need to generate a unique file name for each user, then worry about deleting them afterwards, etc. Plus the added system overhead of writing these files. For my situation, at least, this isn't the solution.

I think I'm just going to go with the original idea, of using response.buffer to display the message. I'll use DHTML to get rid of it when the page is complete. I can put the code into an include file that I'm already using, so I don't have to change every page.

Thanks for all the suggestions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top