Cannot redirect after HTTP headers have been sent
-
Hi! My reporting service is running slow and hence I want to print a message 'Generating report please wait......' by using the java script below: // Write div tag to the page that will contain the text for the progress bar. Response.Write("
"); Response.Write("_"); Response.Write("
"); Response.Write("mydiv.innerText = '';"); // Javascript to do the work of the progress bar. // There are three functions. // 1. ShowWait: Sets text of the div tag to "Loading" followed by 10 periods ".........." // 2. StartShowWait: Calls the ShowWait function every second and make the div tag visible. // 3. HideWait: Hides the div tag when the page is done loading. It is called from a script block // that you need to add to the HTML page as the last element. Response.Write(";"); Response.Write("var dots = 0;var dotmax = 20;function ShowWait()"); Response.Write("{var output; output = 'Generating report please wait';dots++;if(dots>=dotmax)dots=1;"); Response.Write("for(var x = 0;x < dots;x++){output += '.';}mydiv.innerText = output;}"); Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; window.setInterval('ShowWait()',1000);}"); Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';window.clearInterval();}"); Response.Write("StartShowWait();"); Response.Buffer = true; Response.Flush(); Then I am doing response.redirect and I get an error message as mentioned in the subject, can anyone help????????? Many Thanks in advance. happy coding!
-
Hi! My reporting service is running slow and hence I want to print a message 'Generating report please wait......' by using the java script below: // Write div tag to the page that will contain the text for the progress bar. Response.Write("
"); Response.Write("_"); Response.Write("
"); Response.Write("mydiv.innerText = '';"); // Javascript to do the work of the progress bar. // There are three functions. // 1. ShowWait: Sets text of the div tag to "Loading" followed by 10 periods ".........." // 2. StartShowWait: Calls the ShowWait function every second and make the div tag visible. // 3. HideWait: Hides the div tag when the page is done loading. It is called from a script block // that you need to add to the HTML page as the last element. Response.Write(";"); Response.Write("var dots = 0;var dotmax = 20;function ShowWait()"); Response.Write("{var output; output = 'Generating report please wait';dots++;if(dots>=dotmax)dots=1;"); Response.Write("for(var x = 0;x < dots;x++){output += '.';}mydiv.innerText = output;}"); Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; window.setInterval('ShowWait()',1000);}"); Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';window.clearInterval();}"); Response.Write("StartShowWait();"); Response.Buffer = true; Response.Flush(); Then I am doing response.redirect and I get an error message as mentioned in the subject, can anyone help????????? Many Thanks in advance. happy coding!
-
Just do NOT use Response.Flush() - and you will be happy (can Redirect). I can`t explain "why" - I just get the same problem and found that solution... (web-master of RosCosmos)
-
Hi! My reporting service is running slow and hence I want to print a message 'Generating report please wait......' by using the java script below: // Write div tag to the page that will contain the text for the progress bar. Response.Write("
"); Response.Write("_"); Response.Write("
"); Response.Write("mydiv.innerText = '';"); // Javascript to do the work of the progress bar. // There are three functions. // 1. ShowWait: Sets text of the div tag to "Loading" followed by 10 periods ".........." // 2. StartShowWait: Calls the ShowWait function every second and make the div tag visible. // 3. HideWait: Hides the div tag when the page is done loading. It is called from a script block // that you need to add to the HTML page as the last element. Response.Write(";"); Response.Write("var dots = 0;var dotmax = 20;function ShowWait()"); Response.Write("{var output; output = 'Generating report please wait';dots++;if(dots>=dotmax)dots=1;"); Response.Write("for(var x = 0;x < dots;x++){output += '.';}mydiv.innerText = output;}"); Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; window.setInterval('ShowWait()',1000);}"); Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';window.clearInterval();}"); Response.Write("StartShowWait();"); Response.Buffer = true; Response.Flush(); Then I am doing response.redirect and I get an error message as mentioned in the subject, can anyone help????????? Many Thanks in advance. happy coding!
Take a look at ASPX Preloader[^], it sounds like what you are trying to do. Visit BoneSoft.com
-
Hi! My reporting service is running slow and hence I want to print a message 'Generating report please wait......' by using the java script below: // Write div tag to the page that will contain the text for the progress bar. Response.Write("
"); Response.Write("_"); Response.Write("
"); Response.Write("mydiv.innerText = '';"); // Javascript to do the work of the progress bar. // There are three functions. // 1. ShowWait: Sets text of the div tag to "Loading" followed by 10 periods ".........." // 2. StartShowWait: Calls the ShowWait function every second and make the div tag visible. // 3. HideWait: Hides the div tag when the page is done loading. It is called from a script block // that you need to add to the HTML page as the last element. Response.Write(";"); Response.Write("var dots = 0;var dotmax = 20;function ShowWait()"); Response.Write("{var output; output = 'Generating report please wait';dots++;if(dots>=dotmax)dots=1;"); Response.Write("for(var x = 0;x < dots;x++){output += '.';}mydiv.innerText = output;}"); Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; window.setInterval('ShowWait()',1000);}"); Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';window.clearInterval();}"); Response.Write("StartShowWait();"); Response.Buffer = true; Response.Flush(); Then I am doing response.redirect and I get an error message as mentioned in the subject, can anyone help????????? Many Thanks in advance. happy coding!
Suj_78 wrote:
Then I am doing response.redirect and I get an error message
you can't redirect the page by Response.Redirect() after you have sent content to the client. The reason for this is that a Response.Redirect() sends a StatusCode to the browser to indicate that the content has moved to a different location, and the browser should check there. This StatusCode is send in the first line of headers to the browser. If you write content to the browser first you cannot then re-send that header. A solution could be to include:
which would redirect the browser to http://www.someplace.com/somepage.aspx after 3 seconds. see this link for more info: http://www.html-reference.com/META_httpequiv_refresh.htm[^] hope that helps. nicko