Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Cannot redirect after HTTP headers have been sent

Cannot redirect after HTTP headers have been sent

Scheduled Pinned Locked Moved ASP.NET
helpjavajavascripthtmltools
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Suj_78
    wrote on last edited by
    #1

    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!

    P B N 3 Replies Last reply
    0
    • S Suj_78

      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!

      P Offline
      P Offline
      Pimenov
      wrote on last edited by
      #2

      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)

      S 1 Reply Last reply
      0
      • P Pimenov

        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)

        S Offline
        S Offline
        Suj_78
        wrote on last edited by
        #3

        But did you notice that if you don't use flush, it takes time to load the message and hence doesn't serve its purpose. happy coding!

        1 Reply Last reply
        0
        • S Suj_78

          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!

          B Offline
          B Offline
          BoneSoft
          wrote on last edited by
          #4

          Take a look at ASPX Preloader[^], it sounds like what you are trying to do. Visit BoneSoft.com

          1 Reply Last reply
          0
          • S Suj_78

            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!

            N Offline
            N Offline
            nicko
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups