By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,742 Members | 793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,742 IT Pros & Developers. It's quick & easy.

Performing a download along with another action

P: n/a
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
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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" <nj********@hotmail.com> wrote in message
news:Ol**************@TK2MSFTNGP14.phx.gbl...
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
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 20 '05 #2

P: n/a
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" <nj********@hotmail.com> wrote in message
news:Ol**************@TK2MSFTNGP14.phx.gbl...
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
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 20 '05 #3

P: n/a
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
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.