Reload calling page in ASP.NET 2.0

Discussion in 'ASP .Net' started by J055, Jun 5, 2007.

  1. J055

    J055 Guest

    Hi

    I have a list on LinkButton controls on a page. When the link is clicked the
    LinkButton.Command event does a Server.Transfer to a page which writes
    binary to the HTTP output stream, e.g. a word document, pdf etc.

    Response.BinaryWrite(buffer);
    Response.End();

    I would like to reload the page with the LinkButtons after this event to
    reflect changes which are made after the download of the file.

    I understand that some client script may be needed but I'm not sure how to
    implement this or if something can be added to the LinkButton.OnClientClick
    property.

    I'm guessing that maybe I need to do a postback and then write some client
    script to open the download page? What's the neatest solution please?

    Many thanks
    Andrew
     
    J055, Jun 5, 2007
    #1
    1. Advertising

  2. Hi Andrew,

    When the LinkButton is clicked, in its Command event, you don't use
    Server.Transfer; instead, you use ClientScript.RegisterStartupScript to
    register a script to open the download page in a new window:

    void Link1_Command(object sender, CommandEventArgs e)
    {
    ClientScript.RegisterStartupScript(GetType(), "download",
    "window.open('Download.aspx', '_blank')", true);
    }


    #open Method (window)
    http://msdn2.microsoft.com/en-us/library/ms536651.aspx


    Hope this helps.


    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Jun 6, 2007
    #2
    1. Advertising

  3. I think your idea will be the easiest: on click of the link button on the
    server side, do all the necessary updates and spit out JavaScript code to
    open the binary streaming page. This will let the download start in another
    page but at the same time refresh the current page.

    "J055" wrote:

    > Hi
    >
    > I have a list on LinkButton controls on a page. When the link is clicked the
    > LinkButton.Command event does a Server.Transfer to a page which writes
    > binary to the HTTP output stream, e.g. a word document, pdf etc.
    >
    > Response.BinaryWrite(buffer);
    > Response.End();
    >
    > I would like to reload the page with the LinkButtons after this event to
    > reflect changes which are made after the download of the file.
    >
    > I understand that some client script may be needed but I'm not sure how to
    > implement this or if something can be added to the LinkButton.OnClientClick
    > property.
    >
    > I'm guessing that maybe I need to do a postback and then write some client
    > script to open the download page? What's the neatest solution please?
    >
    > Many thanks
    > Andrew
    >
    >
    >
     
    =?Utf-8?B?U2l2YSBN?=, Jun 6, 2007
    #3
  4. J055

    J055 Guest

    Hi

    Thanks for the advise. I need to include some querystring parameters. The
    window.open method doesn't seem to support a querystring, e.g.

    onclick="window.open('Download.aspx?ID=1234');"

    I guess i need a javascript function? How would I add the function to the
    aspx page?

    Thanks
    Andrew
     
    J055, Jun 6, 2007
    #4
  5. Hi Andrew,

    The window.open function can open a URL with querystring; your code looks
    fine, I'm not sure what's the issue you're having?

    To add a javascript function in the page, you can use
    ClientScript.RegisterClientScriptBlock or
    ClientScript.RegisterClientScriptBlock.


    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Jun 7, 2007
    #5
  6. J055

    J055 Guest

    Hi Walter

    There's a problem with the VS web server and IE7. It works ok in Firefox
    using the local server. I get this message in IE when clicking the link with
    the querystring.

    "Internet Explorer cannot download Download.aspx from localhost. Internet
    Explorer was not able to open this internet site. The requested site is
    either unavailable or cannot be found. Please try again later."

    I've tested it using an IIS web server and it works ok. The only problem for
    me is that it opens a blank window as well as a file download pop up window.
    Do you know if I can stop the new window displaying?

    Thanks again
    Andrew


    "Walter Wang [MSFT]" <> wrote in message
    news:...
    > Hi Andrew,
    >
    > The window.open function can open a URL with querystring; your code looks
    > fine, I'm not sure what's the issue you're having?
    >
    > To add a javascript function in the page, you can use
    > ClientScript.RegisterClientScriptBlock or
    > ClientScript.RegisterClientScriptBlock.
    >
    >
    > Regards,
    > Walter Wang (, remove 'online.')
    > Microsoft Online Community Support
    >
    > ==================================================
    > When responding to posts, please "Reply to Group" via your newsreader so
    > that others may learn and benefit from your issue.
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
     
    J055, Jun 7, 2007
    #6
  7. Hi Andrew,

    Please try following two WebForm:

    Default2.aspx:

    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
    Link1.Command += new CommandEventHandler(Link1_Command);
    }

    void Link1_Command(object sender, CommandEventArgs e)
    {
    ClientScript.RegisterStartupScript(GetType(), "download",
    "window.open('Download2.aspx?id=123', '_blank')", true);
    }

    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:LinkButton ID="Link1" runat="server"
    Text="Download"></asp:LinkButton>
    </div>
    </form>
    </body>
    </html>


    Download2.aspx:

    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
    string id = Request.QueryString["id"];
    DownloadFile(new System.IO.FileInfo(@"c:\1.bin"));
    }

    void DownloadFile(System.IO.FileInfo fi)
    {
    Response.AddHeader("Content-Disposition", "attachment; filename=" +
    fi.Name);
    Response.AddHeader("Content-Length", fi.Length.ToString());
    Response.ContentType = "application/octet-stream";
    Response.WriteFile(fi.FullName);
    Response.End();
    }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
    </body>
    </html>



    In Download2.aspx, you should be able to get the querystring id and use
    this to download different file.

    Also, I didn't see the empty window left open when the file is downloaded
    on IE7.


    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Jun 8, 2007
    #7
  8. Hi Andrew,

    I'm wondering if you have tried the code in my last reply. Please feel free
    to let me know if there's anything else I can help.


    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Jun 13, 2007
    #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. Joshua Beall
    Replies:
    26
    Views:
    223,323
    AndreiKaa
    Jun 29, 2007
  2. gen_tricomi
    Replies:
    2
    Views:
    814
    gen_tricomi
    May 23, 2006
  3. Chuck
    Replies:
    0
    Views:
    282
    Chuck
    Jul 5, 2003
  4. Divya
    Replies:
    2
    Views:
    216
    Bullschmidt
    May 11, 2004
  5. Stefan Mueller
    Replies:
    4
    Views:
    337
    Stefan Mueller
    Nov 5, 2005
Loading...

Share This Page