Response.Redirect after Response.Flush

  • Thread starter Thread starter Glen Wilkin via DotNetMonster.com
  • Start date Start date
G

Glen Wilkin via DotNetMonster.com

Is there a way I can call Response.Redirect after I've done a
Response.Flush?
I send some html to load an animated gif that plays whilst my page loads,
it has some extensive database calls to process. However, when I try to
redirect to my error handling page, if there is an error, I get a 'Cannot
redirect after HTTP headers have been sent' error.
I've got round the problem by using a javascript function in the body
onload event that checks a hidden field whose value is set when an error
ocuurs, but this does seem very elegant.
Any ideas?
 
Sorry I meant to say that the javascript fix is NOT very elegant.
 
Just as the error states, you cannot do a redirect once headers, or any
parge of the page, has been sent to the client. An alternative to what you
are doing would be to just write client side script directly into the
response.
i.e.
Response.Write("<script
language=javascript>window.navigate('mynewpage.aspx);</script>")
Response.End

The above script is not a function so it will execute inline immediately
when sent to the browser and direct client to another page. Think of it as
an immediate client side redirect.
 
Back
Top