Reputation: 843
i have a handler that generates a csv file and provide the download, this handler called by button in codebehind on my defoult.aasp like this:
Response.Redirect("~/Handler.ashx?startDate="+tbStartDate.Text.Trim()+"&endDate="+tbEndDate.Text+"&isCheck="+chkDuplication.Checked.ToString());
now I have a another line after above code were should update my list view, but list view not getting updated, is there any way that I can update the list view after csv download.
Thanks,
Upvotes: 1
Views: 1540
Reputation: 6612
try using endResponse attribute which Indicates whether execution of the current page should terminate, make it false so that the line below Response.End gets executed.
When you call Response.Redirect method in an HTTP handler and you want to redirect to another page without terminating the request, set endResponse to false. Soruce - http://msdn.microsoft.com/en-us/library/a8wa7sdt(v=vs.90).aspx
Response.Redirect("url",false);
// code to update your list view
Upvotes: 1
Reputation: 44941
The problem is with your redirect. From the Microsoft documentation:
Any response body content such as displayed HTML text or Response.Write text in the page indicated by the original URL is ignored.
You have a couple of options depending on the processing that needs to occur:
If you do not need to post the page back in order to open the file, you can open a new window in javascript (window.open with a target of '_blank') using your ashx page (including its query string) as the URL.
If your page needs to postback, you can generate the javascript on the server side and have it execute when the page is first reloaded into the browser using Page.ClientScript.RegisterStartupScript.
We actually use both methods depending on the specific requirements. Generally, we prefer the first approach, even if it means a little more work in javascript, but sometimes postbacks can't be avoided.
Upvotes: 2