asp.netdownloaduser-controlspostbackregisterstartupscript

How to refresh UserControl or Call User control function from Parent serverside in ASP.Net C#?


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 .


Solution

  • 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.