PageFlow After HTTPs Write

Discussion in 'ASP .Net' started by GaryDean, Jul 15, 2006.

  1. GaryDean

    GaryDean Guest

    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();
    }
    }
    --
    Regards,
    Gary Blakely
     
    GaryDean, Jul 15, 2006
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    >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();
    > }
    > }
    > --
    > Regards,
    > Gary Blakely
    >
    >
     
    Mark Fitzpatrick, Jul 15, 2006
    #2
    1. Advertising

  3. 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" wrote:

    > 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();
    > }
    > }
    > --
    > Regards,
    > Gary Blakely
    >
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Jul 15, 2006
    #3
  4. GaryDean

    GaryDean Guest

    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 [C# MVP]" <> wrote in message
    news:...
    > 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" wrote:
    >
    >> 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();
    >> }
    >> }
    >> --
    >> Regards,
    >> Gary Blakely
    >>
    >>
    >>
     
    GaryDean, Jul 15, 2006
    #4
  5. GaryDean

    GaryDean Guest

    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" <> wrote in message
    news:%239R09$...
    > 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" <> wrote in message
    > news:...
    >>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();
    >> }
    >> }
    >> --
    >> Regards,
    >> Gary Blakely
    >>
    >>

    >
    >
     
    GaryDean, Jul 15, 2006
    #5
  6. 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.
     
    Steven Cheng[MSFT], Jul 17, 2006
    #6
  7. GaryDean

    GaryDean Guest

    Steven,
    That all makes sense except that when I do
    string myURL = http://localhost/ReportServer/Pages/ReportViewer.aspx? etc
    etc....;
    Response.Redirect(myURL)"
    noone is hitting a "Export" button. I'm just doing a Response.Redirect.

    Have we somehow found a way to instantiate a new browser window from server
    code? I don't know how its working.
    --
    Regards,
    Gary Blakely
    "Steven Cheng[MSFT]" <> wrote in message
    news:6Rz7$...
    > 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.
    >
     
    GaryDean, Jul 18, 2006
    #7
  8. 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.
     
    Steven Cheng[MSFT], Jul 19, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Heiner Kücker

    JSP Workflow FlowControl PageFlow Engine

    Heiner Kücker, Nov 25, 2004, in forum: Java
    Replies:
    1
    Views:
    3,104
    Murray
    Nov 25, 2004
  2. smwikipedia
    Replies:
    2
    Views:
    407
    smwikipedia
    Mar 26, 2008
  3. Axel
    Replies:
    8
    Views:
    1,266
    Adrienne Boswell
    Apr 27, 2009
  4. jotto
    Replies:
    4
    Views:
    441
    jotto
    Oct 2, 2006
  5. Naveen Dhanuka
    Replies:
    1
    Views:
    319
Loading...

Share This Page