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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Response.Redirect does not allow display of html? 4

Status
Not open for further replies.

ahmun

IS-IT--Management
Jan 7, 2002
432
US
I have a page that dynamically creates a PDF based on data from a database. Once the code loops through the various tables and assembles the data, I use a response.redirect to take the user directly to the pdf file.

I would like to put up a simple "please wait while the pdf is generated" message on the screen, but for some reason, if I have a response.redirect on the screen, no html will show.

I've tried to set the buffer to true, and then response.flush it after the closing </html> tag, then running the response.redirect after the flush, but nothing happens... and the &quot;please wait...&quot; message is displayed, but I have stopped all processes.

so it goes a little something like this:

Scenario 1: Body info doesn't show up
Code:
<html>
<header stuff...>
<body>
<p>Please wait while the pdf is generated...</p>
</html>
<%
  'the serious code goes here...
  'the code finishes and writes a pdf file...
  response.redirect &quot;/docs/somePDF.pdf&quot;
%>
Scenario 2: Use of response.buffer
Code:
<% response.buffer = true %>
<html>
<header stuff...>
<body>
<p>Please wait while the pdf is generated...</p>
</html>
<%
  response.flush

*********************
'I do the flush here to try to get the browser to see the HTML text before I run the code... in hopes that I can allow the user to see that message, then generate the pdf, then response.redirect the user to the dynamically generated file
*********************
Code:
  'the serious code goes here...
  'the code finishes and writes a pdf file...
  response.redirect &quot;/docs/somePDF.pdf&quot;
%>


Earnie Eng
 
faq333-3223

more so turn the buffer &quot;off&quot;

_____________________________________________________________________
[sub]Where have all my friends gone to????[/sub]
onpnt2.gif

 
It appeard to work... but then I scrolled down and saw this error (line 26 is where my response.redirect is located):
Code:
Response object error 'ASP 0156 : 80004005' 

Header Error 

/EmployeePhoneList/createPhoneList_AllRegions.asp, line 26 

The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.



Earnie Eng
 
How about like this?
<% response.buffer = true %>
<html>
<header stuff...>
<body>
</body>
</html>
<%
Response.write &quot;<div>Please wait while the pdf is generated...</div>&quot;
Response.flush()

'the serious code goes here...

%>

 
thread333-629608

you cannot redirect after you write to the browser



_____________________________________________________________________
[sub]Where have all my friends gone to????[/sub]
onpnt2.gif

 
Yes... veep... I've tried the response.flush thing, but it had the same behavior as setting the buffer to true, except no error message...

if.. response.redirect doesn't work after writing to the browser.. what options do I have?

Earnie Eng
 
You could do my stupid IE only form trick and &quot;POST&quot; the user to the page you want them to go to.
 
a stoopid &quot;POST&quot; trick?

Earnie Eng
 
If your browser audiance is IE then you could do something like this:
<%
'the serious code goes here...
'the code finishes and writes a pdf file...
%>
<form name=&quot;myForm&quot; action=&quot;/docs/somePDF.pdf&quot; method=&quot;post&quot;>
</form>
<script language=&quot;vbscript&quot;>
myForm.Submit()
</script>

 
would this work for all browsers if I used javascript instaed of vbscript?

Code:
<form name=&quot;myForm&quot; action=&quot;/docs/somePDF.pdf&quot; method=&quot;post&quot;></form>

<script language=&quot;javascript&quot;>
  document.myForm.Submit()
</script>

Earnie Eng
 
I don't think that this will submit the form.
<script language=&quot;javascript&quot;>
document.myForm.Submit()
</script>

That's why I used VBScript. If you can make it work with js let me know. Thanks.
 
it would submit it but javascript is case sensitive so try
<script language=&quot;javascript&quot;>
document.myForm.submit();
</script>

note the lower &quot;s&quot; and the &quot;;&quot; syntax



_____________________________________________________________________
[sub]Where have all my friends gone to????[/sub]
onpnt2.gif

 
Thanks onpnt! :) You have no idea how often I forget the case sensitive thing (working with vbscript all the time). After I responded I decided to try it just for yucks. Of course (cut n' paste) it didn't work. Once again you're there to clean up my mess. ;-)
 
hi veep, onpt...

the &quot;stoopid&quot; form/submit thing works.. but the submit fires before my heavy code finishes its work!

Earnie Eng
 
How about (I'm braindead and grasping at straws)?

<%
'the serious code goes here...
'the code finishes and writes a pdf file...
response.write(&quot;<form name=&quot;&quot;myForm&quot;&quot; action=&quot;&quot;/docs/somePDF.pdf&quot;&quot; method=&quot;&quot;post&quot;&quot;></form>&quot;)
response.write(&quot;<script language=&quot;&quot;javascript&quot;&quot;>&quot;)
response.write(&quot;document.myForm.submit();&quot;)
response.write(&quot;</script>&quot;)
%>
 
You guys appear to be having fun, can't let you keep it all to yourselves :)

How about just using a meta refresh? You could put it on a 0 second redirect which will allow your &quot;please wait&quot; screen to sit there until the other one begins to load...

-Tarwn

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
AAH...Finally, the trees through the forest. [spineyes]
Thanks for joining in on the fun!
 
my long lost friend is here. thought those 50 hour days did you in.

[smile]

_____________________________________________________________________
[sub]Where have all my friends gone to????[/sub]
onpnt2.gif

 
can you further explain the meta things? I've seen meta tags automatically generated by frontpage.. but I have not a clue what they are...

Earnie Eng
 
Here is Tarwn's idea:

<META HTTP-EQUIV=&quot;refresh&quot; content=&quot;0;/docs/somePDF.pdf&quot;>

Put that inside the <HEAD> tag.
Tarwn really is a genius! :-D

Medic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top