Monday, July 07, 2008

Download File with ajax

script language="javascript"

// Get a PageRequestManager reference.
var prm = Sys.WebForms.PageRequestManager.getInstance();

// Hook the _initializeRequest event and add our own handler.
prm.add_initializeRequest(InitializeRequest);

function InitializeRequest(sender, args)
{
// Check to be sure this async postback is actually
// requesting the file download.
if (sender._postBackSettings.sourceElement.id == "DownloadFile")
{
// Create an IFRAME.
var iframe = document.createElement("iframe");

// Get the desired region from the dropdown.
var region = $get("Region").value;

// Point the IFRAME to GenerateFile, with the
// desired region as a querystring argument.
iframe.src = "GenerateFile.aspx?region=" + region;

// 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);
}
}
/script






http://encosia.com/2007/02/23/ajax-file-downloads-and-iframes/


0 comments: