Using Response.Redirect() after Response.Flush()

I wonder if anyone might be able to help me with a problem I'm having in redirecting to a new page after calling Response.Flush();

The problem has arisen as a side effect of implementing a "Please Wait..." page that displays when clicking on a Search button. The following code is executed when the button's Click event is run:

private void btnConfirm1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
btnConfirm1.Visible = false;
Response.Buffer = true;
FileStream oFile = new FileStream(Request.PhysicalApplicationPath
+ "/Content/WaitPage.config",FileMode.Open, FileAccess.Read);

StreamReader oReader = new StreamReader(oFile);
string sPageText;
while ((sPageText = oReader.ReadLine()) != null)
// Processing begins
// Processing ends
Response.Write("<script language=\"javascript\">\ndocument.getElementById
('PleaseWait').style.display = 'none';\n</script>");

The file WaitPage.config in effect constitutes a complete web page, including a header etc. The entire content of the page, apart from the header lives within the <DIV> 'PleaseWait'.
The problem that I'm having is that clicking the browser refresh button once processing is complete and you are returned to the page produces a runtime error -"System.Web.HTTPException: Cannot redirect after HTTP headers have been sent." This is a result of a Response.Redirect() to another page, and I understand that calling Response.Flush() produces this behaviour.
Does anyone have any suggestions as to how I might use redirection to another page without producing this error?

11/5/2003 3:31:53 PM 91979 articles. 4 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 32
Get it on Google Play
Get it on Apple App Store

You can't do that. It does not make much sense by the way, as redirect sends a header to the browser that orders it to immediately go to another page. So whatever you flushed will never be seen by anyone anyway.

You should check out the Asynchronous Application Block from MSDN as it is a much much cleaner way of doing this.
Does this help?
This posting is provided "AS IS" with no warranties, and confers no rights.
11/8/2003 3:03:52 AM

Similar Artilces:

Should we use Response.Redirect ( url, true) or Response.Redirect ( url, false) ?
Normally most of the time we use Response.Redirect (url). How is this different from Response.Redirect ( url, true) or Response.Redirect ( url, false) ? Also, what is the best form of Redirect to use when going to another page?sun21170 The second parameter of Response.Redirect is endResponse which is boolean value that indicates whether to stop running the current page.It depends on if you want to keep it alive or stop it.Thanks Mark post(s) as "Answer" that helped youElectronic ScrewWebsite||Blog|| In what situation, would someone pass a true for the endResponse ...

No response from response.redirect
Hi, my project has atleast 10 webforms and for navigation the response.redirect was working fine till today. It stopped working in one of the pages but stills fine in the other pages. eg. the CANCEL button loads the previously navigated page. All CANCEL except one are working. I checked the button click event, put labels with messages in them; the labels get posted when the button is clicked; but when i remove the labels and put in the response.redirect("PAGE NAME") it stopped working; i even put the wrong path in the response.redirect, still the errorhandler or any o...

Using Response.Redirect and Response.Write from flat class file
Setup: I developed an interface that holds certain functions that are shared between some users in my system. The different users are grouped into classes that implement that interface. Problem: In some instances the implementations of this interface include a mere write to the screen or a redirect. However, when I attempt to do something like Response.write or Response.redirect from those classes, I am getting an error that says "Response is not Available in this Context" Question: Is what I am trying to do possible and if so, how do I correct this problem. ...

How can I get a Response.Write and Response.Redirect to work one following the other?
I have a button on my webform that needs to perform 2 operations.  First it must open a new window which I usually do like this: sJScript = "<script>'Form01.aspx?ID=0&Parent=5', '', '');</script>"Response.Write(sJScript)Second it must redirect the current page (not the newly opened one).  I usually do that like this:Response.Redirect("Form02.aspx?ID=6")My problem is, in this case, I must do both with one button click and they interfere with each other.  I've tried flushing/ending the response object in various places, re ordering things, etc but n...

Won't let me use both Response.Write and Response.Redirect in same function?
Below is my code:Response.Write("&lt;script language='javascript'> ('Saved Form.htm' ,'NewWindowName', 'width=400, height=400, toolbar=no, resizable=no');</script>"); Response.Redirect("forms.aspx?Form=sale");  Those two lines are in a function. When that function is called it directly redirects me to forms.aspx without opening the new window first. How can I fix that so that it opens the new window and then redirects the user to a different page in the old window. Using Visual Studio 2005. Language: C# ...

Response.write or Response.redirect?
I have a code using Response.Write and javascript to open another page, the code looks like this: Response.Write("<Script language='javascript'>'" & Session("varflag") & "&vid=" & Session("FacilityID") & "&vrepid=" & Session("varid") & "');</script>") it send me to another page in a different window or tab. I want to open it in the same window or tab as in Response.Redirect, but in Respons...

Query Parameter Getting Dropped Using Response.Redirect
I have a http handler that redirects the user to a new web pages based on the value in their query string It worked fine on my workstation but when we migrated to our Development Server, things went awry I can not debug on the server due to company policy, so I am shooting in the dark  We are using Siteminder security When Siteminder challanges, the parameter gets lost When Siteminder does not challenge, it works fine Our Web Eng folks have confirmed that the parameter is coming back from Siteminder For example: url: http://Website/Handler?instanceId=04adef5e-5b23-49d3-a085-5eb...

How to get the value from one page to another page when i use response.redirect
I have two webforms, webform1 and webform2i am doing the response.redirect on webform1 to get onto webform2.I am doing the following:response.redirect("webform2.aspx?ID=23")Now on webform2.aspx i only have Javascript functions.How can i get the value of my response.querystring("ID") into the javascript function.I am calling this javascript function of forms onload.I have the functions on the html window only not using the code behind.Please i have real difficulty. Help me.Thank you very much for the information. Hi,Try below code in your webform2.aspx. Private Sub Page_Loa...

How to get previous page info when i use response.reidrect() for page redirect
 Hi All,         I have two pages like default.aspx and home.aspx.         On default.aspx page i have a button when i click the button then i am using response.redirect         for going on home.aspx.          On home i wanted to get previous page name,url,ip address,project name,username like this.         I tried Request.Urlreferal but it is not working.        So please give me help. Thanks,Pankaj Kumar Singh      &...

Why I can't get back to the page I want by use Response.Redirect(path)?
My code is below , my problem is ... the code works find except I add the "" I was thought page should back to the list page () after the comfirmd message Box is return "true" yes, after I add the code (Line 10) , page did return the List page , but before it returned , is shows a error message why? can you please help me to fix my code to avoid system show the error message again? thank you very much  1 protected void btnSave_Click(object sender, EventArgs e) 2 { 3 try 4 { 5 ................... 6 ...

Not able to use Response.write for writing to Excel, when using Response content compression
We have the Excel download option for our page, for which we use Response.ContentType as application/ and writing the data to Excel stream using Response.write.  As we apply Respone fileter for compressing the response content, this is not working. Considering the performance we don't want to disable the compression.  can anyone give some suggestions? Thanks in advance.     Disabling the compression for these particular requests would be OK, wouldn't it?However, a compressing response filter should not be a problem, even with application/vnd....

Response.Redirect after response.OutputStream.Write?
I'm using the Wrox Docs module from Building An ASP.NET Intranet. This code outputs the doc from the DB to the client Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim ItemID As Integer = -1 Dim strTable As String = "parent" Dim DocsSec As New WroxDocSecurity() 'comment this code if you don't want to lock down the download process If Not (DocsSec.HasDocPermissions(DocumentPermissions.DownloadandViewOnly, Request.Params("key"))) _ ...

How to use response.transmitfile or response.writefile ?
I'm accessing an excel file stored in an image field in a database. I want to write it out to a folder. DocumentSize = (int)dr["Size"]; byte[] BytesBuf = new byte[DocumentSize]; BytesBuf = (byte[])dr["Content"]; Response.Clear();Response.ContentType = "application/"; Response.OutputStream.Write(BytesBuf, 0, DocumentSize); Response.AppendHeader("Content-Disposition", "attachment; filename=out.xls"); Response.TransmitFile(System.IO.Path.Combine(Server.MapPath("~/Documents"), "out.xls")); ...

How to catch page not found when redirecting using response.redirect.
There is a virtual path(http://server1/files/test.xls). From web app, I have to redirect to above path. If test.xls does not exist in the path, I have to display unauthorized page. I tried using if (File.Exists(Server.MapPath(URL))) but it gives an error "it is not a valid virtual path". Please help.If this answered your question, please mark as an answer so others will know too. you can do a default redirect on a 404 by setting it in the web.config <customErrors mode="RemoteOnly" defaultRedirect="~/Misc/ErrorPage.aspx">    &n...

Web resources about - Using Response.Redirect() after Response.Flush() -

America's Response Monument - Wikipedia, the free encyclopedia
dedicated to the United States Special Forces and commemorates the servicemen and women of America’s Special Operations response to 9/11, including ...

WA fires: DFES defends response times to devastating Yarloop fires
Department of Fire and Emergency Services commissioner Wayne Gregson has defended his department's response times to the South West fires after ...

Antibodies to our own proteins may predict adverse vaccine responses
(credit: Art Writ ) Let's get something straight from the start: vaccines are good. Let's be completely clear about that. But sometimes some ...

GOOD NEWS: Apple Buys Technology That Uses Your Phone’s Camera to Gauge Emotional Response to Ads
... better understand consumer reactions to engagements. Given the iPhone’s camera, the possibilities seem endless: • Gauge the emotional response ...

Five possible responses to the Google-Motorola merger
When big acquisitions are announced, there's likely an aftershock that reverberates through an industry. CNET takes a look at some possible scenarios ...

Giuliani Says Trump’s Response To Hillary Calling Him A ‘Sexist’ Was ‘Politically Brilliant’
Giuliani Says Trump’s Response To Hillary Calling Him A ‘Sexist’ Was ‘Politically Brilliant’

Abbreviated pundit roundup: 'A national crisis like this demands a national response'
... Barack Obama , who held a live town hall on CNN on reducing gun violence yesterday: A national crisis like this demands a national response. ...

Catcher cuts capex for 2016 in response to client orders
Catcher Technology is planning to cut its capex for 2016, and the amount will be much lower than those budgeted in the past two years in response ...

Amy Schumer Has the Perfect Response to Talk About Her New Boyfriend: This is Apparently My 'Biggest ...
Amy Schumer Has the Perfect Response to Talk About Her New Boyfriend: This is Apparently My 'Biggest Accomplishment'

Consumers Dissatisfied With Interactive Voice Response
Often, respondents reported being frustrated by interactive voice responses (IVRs) that replicated information already available on the website. ...

Resources last updated: 1/11/2016 1:05:16 PM