Tuesday, 22 January 2013 13:56

how to download file when file download button inside updatepanel

Written by 
Rate this item
(0 votes)

many times when file download button inside updatepanel and you use
Page.Response methods for file downloading then things not go right
in some cases.

following techniques shows ways to solve the problem using iframe.

there is a button in gridview with class FileItemClass.when clicked
it first gets the file path stored in a input control in the gridview
by row.find("td:eq(2) input").val(); then a iframe created and its source
url is set to another file with file path as querystring.in this files page
load event the codes will be written to download files using Page.Response or
other methods for downloading files.

function pageLoad() {
$(".FileItemClass").click(function () {
var iframe = document.createElement("iframe");
var row = $(this).closest("tr");
var annid = row.find("td:eq(2) input").val();
iframe.src = "../FileDownload.aspx?fpath=" + row.find("td:eq(2) input").val();
// This makes the IFRAME invisible to the user.
iframe.style.display = "none";

// Add the IFRAME to the page. This will trigger
//a request to GenerateFile now.
document.body.appendChild(iframe);
return false; //tis magic
});
};

Read 3083 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.
Login to post comments