Showing posts with label webform. Show all posts
Showing posts with label webform. Show all posts

Monday, March 26, 2012

Performing a download along with another action

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
njsokalski@dotnet.itags.org.hotmail.com
http://www.nathansokalski.com/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" <njsokalski@.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
> njsokalski@.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

"Nathan Sokalski" <njsokalski@.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
> njsokalski@.hotmail.com
> http://www.nathansokalski.com/
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

Performing a download along with another action

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
njsokalski@dotnet.itags.org.hotmail.com
http://www.nathansokalski.com/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" <njsokalski@.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
> njsokalski@.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
"Nathan Sokalski" <njsokalski@.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
> njsokalski@.hotmail.com
> http://www.nathansokalski.com/
>
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

Friday, March 16, 2012

persist values from one postback to another

Hi,

Not sure if the title makes sense but heres my dilemma. I have two
dropdownlist controls on a webform. I want to make sure that the first
dropdownlist control was clicked on and a value was selected. I want to check
in the second dropdownlist control that this has happened before processing
any info. I thought I would set a boolean in the selected event of the first
ddl control but when the event fires for the second ddl control the boolean
is set back to false due to the page reloading, I assume. How can I persist
that boolean value between postbacks? And for this scenario what is the best
way to achieve my goal if the way im describing is not the best?

Thanks,

JJTake a look at requiredFieldValidator and custom validator
The easiest way to handle this is to simply check and ensure the first
control is not set to index 0.

if(ddlFirstControl.SelectedIndex==0)
//code to indicate the user did not touch drop down 1
else
//code to process dropdown 2

If you want to persist a boolean (not necessary if the first drop down has
an invalid value, like "choose one"), you can store it in ViewState.

//in Drop down change event for the first drop down
ViewState("FirstControlChanged") = true;

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"JJ" wrote:

> Hi,
> Not sure if the title makes sense but heres my dilemma. I have two
> dropdownlist controls on a webform. I want to make sure that the first
> dropdownlist control was clicked on and a value was selected. I want to check
> in the second dropdownlist control that this has happened before processing
> any info. I thought I would set a boolean in the selected event of the first
> ddl control but when the event fires for the second ddl control the boolean
> is set back to false due to the page reloading, I assume. How can I persist
> that boolean value between postbacks? And for this scenario what is the best
> way to achieve my goal if the way im describing is not the best?
> Thanks,
> JJ