Click to See Complete Forum and Search --> : Response.Binarywrite backbutton problem


marjoh
March 13th, 2008, 04:54 AM
Hi all,

I've made a webpage where you can search for pdf-files. The result is listed in a datagrid. To view a pdf matching the searchcriteria, you simply click on a row in the datagrid, and then the pdf is viewed within the browser.
Problem is that when I push the browsers backbutton I don't come back to the searchresultview, but to the page BEFORE the searchresult.

I'm using Response.BinaryWrite to view the pdf (byteformat), which seems to overwrite the current browser view. When hitting the backbutton, the browser doesn't "remember" the former view, but throws me back to the page before that page ("2 steps back"). Is there a way for me to create a blank page (within the browser), and then view the pdf in that page? That should allow me to go back to the former view when I push the back button...
Or is there another smooth way I can keep the searchresultview and come back to that view when pushing the backbutton?
I don't want to open a new window when watching the pdf.

MikeVallotton
March 13th, 2008, 09:30 AM
Can you use an iFrame to display the PDF?

marjoh
March 14th, 2008, 07:28 AM
I think I somehow have to render a new page...

MikeVallotton
March 14th, 2008, 08:07 AM
I'll just make a different suggestion.

When the user clicks the row in the datagrid, it's posting back to the server and you're using the BinaryWriter to stream the data directly to the browser window.

Since this is technically the same page, the back button won't treat it as two separate pages.

The easiest way I can think of to get around this problem is to make it so that when the user clicks the row in the datagrid, and you postback to the server, you should do a Response.Redirect to another page that uses the BinaryWriter to write to the browser window.

You can pass the particular file you need either on the query string, in a session variable, or in a cookie.

This way the browser will register two distinct pages and the back button will work the way you want.

marjoh
March 14th, 2008, 09:26 AM
What a simple solution! Why on earth didn't I think of that?? Stupid!
Thanks alot man for helping me out.

MikeVallotton
March 14th, 2008, 10:09 AM
No problem. :)