PageFlow After HTTPs Write

G

GaryDean

I have a page that streams PDF documents using the code pasted below. The
Page displays the documents just fine but the user is left with no action
but to hit the back button on the browser which takes him to the page that
redirected to this page where the page load event is not re-executed. It's
just a dead page.

Is there some way I can force a new browser window for this display?

How can I do this display and control the page flow?



---------------------------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
byte[] teststream = (byte[])Session["PDFStream"];
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ContentType = "Application/PDF";
HttpContext.Current.Response.BinaryWrite(teststream);
Response.End();
}
}
 
M

Mark Fitzpatrick

The only thing you could do is have the link itself use the target="top" to
open the PDF page in a new browser window. You can't open a new one through
http or the response object.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
G

Guest

Well,
This is an issue that's pretty common. Once you say "Response.End()" that's
basically it my friend.
You could, if you wanted, do this in another browser window and allow the
user to return to the existing one and do something else.
Hope that helps.
Peter
 
G

GaryDean

If I can't force a new browser page then I am wondering how SQL Server
Reporting Services does it when I code the following:

string myURL = http://localhost/ReportServer/Pages/ReportViewer.aspx? etc
etc....;
Response.Redirect(myURL)"

ReportViewer.aspx is just a page with a ReportViewer control in it but it
renders a new page.

--
Regards,
Gary Blakely
Peter Bromberg said:
Well,
This is an issue that's pretty common. Once you say "Response.End()"
that's
basically it my friend.
You could, if you wanted, do this in another browser window and allow the
user to return to the existing one and do something else.
Hope that helps.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




GaryDean said:
I have a page that streams PDF documents using the code pasted below.
The
Page displays the documents just fine but the user is left with no action
but to hit the back button on the browser which takes him to the page
that
redirected to this page where the page load event is not re-executed.
It's
just a dead page.

Is there some way I can force a new browser window for this display?

How can I do this display and control the page flow?



---------------------------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
byte[] teststream = (byte[])Session["PDFStream"];
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ContentType = "Application/PDF";
HttpContext.Current.Response.BinaryWrite(teststream);
Response.End();
}
}
 
G

GaryDean

If I can't force a new browser page then I am wondering how SQL Server
Reporting Services does it when I code the following:

string myURL = http://localhost/ReportServer/Pages/ReportViewer.aspx? etc
etc....;
Response.Redirect(myURL)"

ReportViewer.aspx is just a page with a ReportViewer control in it but it
renders a new page.

--
Regards,
Gary Blakely
Mark Fitzpatrick said:
The only thing you could do is have the link itself use the target="top"
to open the PDF page in a new browser window. You can't open a new one
through http or the response object.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

GaryDean said:
I have a page that streams PDF documents using the code pasted below. The
Page displays the documents just fine but the user is left with no action
but to hit the back button on the browser which takes him to the page that
redirected to this page where the page load event is not re-executed.
It's just a dead page.

Is there some way I can force a new browser window for this display?

How can I do this display and control the page flow?



---------------------------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
byte[] teststream = (byte[])Session["PDFStream"];
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ContentType = "Application/PDF";
HttpContext.Current.Response.BinaryWrite(teststream);
Response.End();
}
}
 
S

Steven Cheng[MSFT]

Hello Gary,

As for the ASP.NET web page, if you flush out a certain binary document in
the current page response, it will certainly replace the original html page
and the user can not perform further interaction on the original page
unless the user press back button. This limitation is actually due to the
limitation of http response, each http response can only contains content
of a single mine-type. So far, the only way to stream out a binary
document and remain the original page functionable is streaming out the
document in a new separate browser window.

As you mentioned the webform ReportViewer control, I've just performed some
research on it and it is also using the "new browser window" approach. The
"Export" button on the webform reportviewer control is a hyperlink which
point to a location associated with a custom
httphandler("Reserved.ReportViewerControl.axd") , and when we click the
"Export" link, it will open it in a new separate browser window. The
Reserved.ReportViewerControl.axd handler is responsible for streaming out
the certain report (as the requested format) in that new browser windows.

For your scenario, if you do not want to involve an additional httphandler,
you can just add a new page which is dedicated on streaming out document.
And your main page(which will interact with the client user) can use a
hyperlink to link that page(use some querystring paramters to specific
document inforation). How do you think of this?

Please feel free to let me know if you have any other concerns or questions
on this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial

response from the community or a Microsoft Support Engineer within 1
business day is

acceptable. Please note that each follow up response may take approximately
2 business days

as the support professional working with you may need further investigation
to reach the

most efficient resolution. The offering is not appropriate for situations
that require

urgent, real-time or phone-based interactions or complex project analysis
and dump analysis

issues. Issues of this nature are best handled working with a dedicated
Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Thanks for your followup Gary,

So I get that your current concern is how to make the page open a new
browser window (to a certain page) in server-side codebehind code, correct?
Based on my experience, the most popular means to open new browser windows
through server-side code is to programmatically register some client-side
scripts (in code behind). And there are several script functions that can
open new browser window, such as

window.open( url) or window.showModelessDialog( url )

The difference between them is "window.open" will open a new page url in a
new normal brower window while "showModelessDialog" will display a web page
dialog(with no address bar and fixed border and size). And currently most
client browsers have some certain popup blocker installed, such blocker
will prevent "window.open" created new windows to work, this is also what
you need to take care(showModelessDialog is not restricted to popup
blocker).

Below is some web article describing the two script functions:
http://www.javascript-coder.com/window-popup/javascript-window-open.phtml

http://www.webreference.com/js/column90/2.html

And here are some example function on dynamically registering client-script
to open new browser windows to display other pages in ASP.NET page's
server-side code:

===============================
protected void btnOpenNewWindow_Click(object sender, EventArgs e)
{
string url =
"http://localhost/ReportServer/Pages/ReportViewer.aspx?/AdventureWorks+Sampl
e+Reports/Company+Sales";

string script = "window.open('" + url + "');";

Page.ClientScript.RegisterStartupScript(this.GetType(), "open new
window", script, true);
}

protected void btnNewDialog_Click(object sender, EventArgs e)
{
string url =
"http://localhost/ReportServer/Pages/ReportViewer.aspx?/AdventureWorks+Sampl
e+Reports/Company+Sales";

string script = "window.showModelessDialog('" + url + "');";

Page.ClientScript.RegisterStartupScript(this.GetType(), "open new
dialog", script, true);
}
===============================

Hope this helps further.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top