New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Download Files with an Ajaxified Control When Using the AjaxManager
Environment
Product | Progress® Telerik® UI for ASP.NET AJAX AjaxManager |
Description
How can I download files with an ajaxified control with the Telerik AjaxManager?
Solution
The XmlHttpRequest
does not allow you to use the normal response.WriteFile
function for invoking the download for a file from an AJAX-enabled control, which is either placed in the RadAjaxPanel
or ajaxified by the RadAjaxManager
.
C#
Response.WriteFile("~/Your_File");
To work around this issue, use the ResponseScripts
collection of the Telerik AJAX controls to change the location header and to download the file. In the following example, the ResponseScripts
collection will be executed after the Ajax request completes.
C#
RadAjaxPanel1.ResponseScripts.Add(String.Format(@"window.location.href = ""{0}"";", "http://yoursite.com/Your_File"));