1

I have a page with button for download a file, after I press that , I want a user control to be refreshed .that can be done with a function I wrote in UC.

So: How Can I Call a js Function in User_Control from Parent server-side(after user press Download_button to download a file)

I used this code, but it doesn't work?

Page.ClientScript.RegisterStartupScript(this.GetType(),"UpdateReportList", "UpdateReportList();", true);

Note: UpdateReportList() is js function in my user control .

Sara N
  • 1,079
  • 5
  • 17
  • 45

2 Answers2

1

HttpContext.Current.Response.WriteFile(sFilePath) writes the attachment to the entire response body and no other markup or script get appended through Page.ClientScript.RegisterStartupScript(). That's the reason you don't see of triggering UpdateReportList() in the browser.

The approach to be changed, there are couple of other options to achieve this functionality.

  1. Set a cookie instead of Page.ClientScript.RegisterStartupScript() as it's part of response header. Start a javascript timer using setInterval(), request to download, read the cookie, stop the timer, clear the cookie and call UpdateReportList().

  2. Move the entire code to asp.net generic handler (.ashx) and repeat the same steps as described above.

  3. You can think of some other options based on your requirement.

Sudipta Kumar Maiti
  • 1,669
  • 1
  • 12
  • 18
  • It depends on, a file download time is unknown. So a timer can be an option, a post is available. http://stackoverflow.com/questions/1106377/detect-when-browser-receives-file-download. – Sudipta Kumar Maiti Dec 11 '15 at 18:46
1

based on @Sudipta Maiti for my question , and @puddleglum answer in this link Update page after file download I changed my code as this :

on Download button OnClientClick event , I add this lines before returning to server:

setTimeout(function () {
        window.location.reload(1);
    }, 3000);

so I will have a short delay,and then reloading the page.

Community
  • 1
  • 1
Sara N
  • 1,079
  • 5
  • 17
  • 45