frustration with events firing

R

Rob

ok, so im ready to absolutely throw my self right into the monitor,
can anyone explain why certain events fire before others in asp.net?
in my case, after some processing a final download aspx page calls a
download function which writes a file to the browser.. yet after that
is done I want the page to redirect to another page, but no matter
what I try it wont redirect, I know there is something with the way
..net works, I just cant figure it out.

here is simplified version of code

process....
call downloadfile

Sub downloadfile (fullfile as string)
Dim fstream As FileStream = File.Open(fullfile,
FileMode.Open)
Dim fsize As Long = fstream.Length
Dim Buffer(CInt(fsize)) As Byte
fstream.Read(Buffer, 0, CInt(fsize))
fstream.Close()
Response.AddHeader("content-disposition", "attachment;
filename=" + filename)
Response.BinaryWrite(Buffer)
Response.Redirect("main.aspx")<--- this does not fire at
all?
end sub

after the open/save window comes up , the redirect never fires..
thoughts appreciated.
 
H

Hermit Dave

you are sending the file to the user and you need to finish the current
request before the client can make another request. in this case user
Response.Redirect (it executes from client browser) and since the client is
still not done with the last request.. nothing will happen.

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
 
B

bruce barker

your approach will not work. you can not return content and redirect in the
same response.

redirect works by sending a special header with a redirect url. if the
browser sees this header, it loads the url. in your code you are sending a
response, then sending a header which the browser will never see.

-- bruce (sqlwork.com)
 
R

Rob

thank you all for your thoughts.
so how would you do this then? how can you send the file to the
browser, and have the page redirect, or do any other activity AFTER
the file has been written to browser?
 
H

Hermit Dave

you cant thats why most people send the file over using a new window.
ie use a button or a hyperlink with target as _blank and then send the
request for the aspx page that sends the file.
ie its a content type that cannot be open by the browser then it will keep
the user on current page.. but thats about all you can do.

if you find a work around do let me know...
--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top