Performing a download along with another action

Discussion in 'ASP .Net' started by Nathan Sokalski, Nov 16, 2005.

  1. I have a webform that contains a button which I want to do three things:

    1. Delete a record from a database
    2. Let the user download a text file that is generated
    3. Refresh the page to show that the record was deleted

    I am able to do any of these things separately with no trouble. The problem
    occurs when I try to offer a download AND call my refresh method. When I try
    to do a download and call my refresh method, only the download is performed,
    regardless of whether the refresh is called before or after the download.
    Here is snippet of my code that does the download and refresh:


    Me.RefreshEvents()
    Response.ClearContent()
    Response.ContentType = "text/plain"
    Response.AddHeader("content-disposition", "attachment;filename=" &
    downloadname)
    Response.Write(downloadtext)
    Response.End()


    If I comment out five lines that do the download, Me.RefreshEvents() does
    what I want and would expect, but otherwise it appears to do nothing. I
    don't care whether Me.RefreshEvents() is called before or after doing the
    download, as long as they are both done. What can I do to make sure both of
    these tasks get completed?
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
    Nathan Sokalski, Nov 16, 2005
    #1
    1. Advertising

  2. Nathan Sokalski

    Bruce Barker Guest

    when the browser requests a page (like when the user hit the button), the
    browser only expects one document back. you can do one of several options

    1) refesh page and enable a download button
    2) refresh page and use client script to start a download
    3) refresh page and use meta tag to start download

    in all cases you refresh the page and then download the text file.

    -- bruce (sqlwork.com)


    "Nathan Sokalski" <> wrote in message
    news:...
    >I have a webform that contains a button which I want to do three things:
    >
    > 1. Delete a record from a database
    > 2. Let the user download a text file that is generated
    > 3. Refresh the page to show that the record was deleted
    >
    > I am able to do any of these things separately with no trouble. The
    > problem occurs when I try to offer a download AND call my refresh method.
    > When I try to do a download and call my refresh method, only the download
    > is performed, regardless of whether the refresh is called before or after
    > the download. Here is snippet of my code that does the download and
    > refresh:
    >
    >
    > Me.RefreshEvents()
    > Response.ClearContent()
    > Response.ContentType = "text/plain"
    > Response.AddHeader("content-disposition", "attachment;filename=" &
    > downloadname)
    > Response.Write(downloadtext)
    > Response.End()
    >
    >
    > If I comment out five lines that do the download, Me.RefreshEvents() does
    > what I want and would expect, but otherwise it appears to do nothing. I
    > don't care whether Me.RefreshEvents() is called before or after doing the
    > download, as long as they are both done. What can I do to make sure both
    > of these tasks get completed?
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    Bruce Barker, Nov 16, 2005
    #2
    1. Advertising

  3. Nathan Sokalski

    Chris Botha Guest

    This can be done. What is meant by refreshing the page, something like
    re-display the grid?
    So the user hits the button:
    1. You delete the record and re-bind the grid so the user can see the
    changes on this page.
    2. You save the text to be downloaded in a session variable - this is the
    simplest, or on disk, or database record, etc.
    3. You have a Protected string variable, say MustDownLoad, and set it's
    value "Yes", or anything, to be read by Java script.
    4. In the HTML view of the form, right at the bottom, you must add Java
    script to open a new window to download the text:
    <script language="javascript">
    if ("<%=MustDownLoad%>" != "") {
    window.open("Form_DownLoadText.aspx");
    }
    </script>
    5. You create a new form Form_DownLoadText.aspx and in it, you read the text
    from the session variable/disk/record and do the
    Response.ClearContent()
    Response.ContentType = "text/plain"
    yada yada


    "Nathan Sokalski" <> wrote in message
    news:...
    >I have a webform that contains a button which I want to do three things:
    >
    > 1. Delete a record from a database
    > 2. Let the user download a text file that is generated
    > 3. Refresh the page to show that the record was deleted
    >
    > I am able to do any of these things separately with no trouble. The
    > problem occurs when I try to offer a download AND call my refresh method.
    > When I try to do a download and call my refresh method, only the download
    > is performed, regardless of whether the refresh is called before or after
    > the download. Here is snippet of my code that does the download and
    > refresh:
    >
    >
    > Me.RefreshEvents()
    > Response.ClearContent()
    > Response.ContentType = "text/plain"
    > Response.AddHeader("content-disposition", "attachment;filename=" &
    > downloadname)
    > Response.Write(downloadtext)
    > Response.End()
    >
    >
    > If I comment out five lines that do the download, Me.RefreshEvents() does
    > what I want and would expect, but otherwise it appears to do nothing. I
    > don't care whether Me.RefreshEvents() is called before or after doing the
    > download, as long as they are both done. What can I do to make sure both
    > of these tasks get completed?
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    Chris Botha, Nov 16, 2005
    #3
  4. Nathan,

    Maybe a stupid question, why do you not use the HTML command File Field. It
    is a strange name because AFAIK mostly is used Download Button.

    It is the HTML tag <Input type=file>

    Cor
    Cor Ligthert [MVP], Nov 16, 2005
    #4
    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. Joe Bloggs
    Replies:
    1
    Views:
    729
    Sudsy
    Aug 3, 2003
  2. rjweytens
    Replies:
    6
    Views:
    16,054
    rjweytens
    Jun 25, 2004
  3. jeff
    Replies:
    2
    Views:
    281
    Paul Watson
    Jan 23, 2004
  4. vyshu
    Replies:
    1
    Views:
    2,528
    Richard Senior
    Apr 27, 2007
  5. Serge Myrand

    Performing action before moving to another page

    Serge Myrand, Jul 12, 2004, in forum: ASP General
    Replies:
    1
    Views:
    101
    Bullschmidt
    Jul 13, 2004
Loading...

Share This Page