|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Performing a download along with another action1. 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? 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) Show quote "Nathan Sokalski" <njsokal***@hotmail.com> wrote in message news:OluwItk6FHA.2176@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 > njsokal***@hotmail.com > http://www.nathansokalski.com/ > 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 Show quote "Nathan Sokalski" <njsokal***@hotmail.com> wrote in message news:OluwItk6FHA.2176@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 > njsokal***@hotmail.com > http://www.nathansokalski.com/ > |
|||||||||||||||||||||||