downloading a file using jquery in asp.net using vb.net

classact

New Member
I am developing a website that would be accessible only within our organisation I want to implement a functionality in which client will download a file (Visio File *.vsd) from server and save it to any location.I successfully implemented the functionality. I did the folowing steps.[*]whenever user will click an option a function in .js is fired.[*]In that function i create an . Inside the iframe I have a tag consisting textboxes whose values will be passed as params to server. [*]I have created a handler (*.ashx) which gets the request when I submit the form contained in the IFrame.[*]At server side I get the request and depending upon the parameters I create a response and send it to the client (I send visio file as response).[*]The user receives the response and see's the saveAs dialog box and saves the file.This works great for the first time, however i get an error named "Access denied" when I try to access iFrame elements(i.e textboxes) for the second time. For reference I have given the code here.\[code\]function FileHandler(){ var spnExcelFile; this.init = function() { spnExcelFile = document.getElementById("spnGetExcelFile"); spnExcelFile.onclick = function(e) { getExcelFile(); } } var getExcelFile = function() { var frmWindow = getIFrameWindow(); var fileName = frmWindow.document.getElementById("fileName"); // **Gives me error over here when called for second time.** fileName.value = http://stackoverflow.com/questions/14050715/encodeURI("ExcelFile.xls"); var frm = frmWindow.document.getElementById("frmFile"); frm.submit(); } var getIFrameWindow = function() { var ifr = document.getElementById("fileFrame"); if (!ifr) { createFrame(); } var wnd = window.frames["fileFrame"]; return wnd; } var createFrame = function() { var frame = document.createElement("iframe"); frame.name = "fileFrame"; frame.id = "fileFrame"; document.body.appendChild(frame); generateIFrameContent(); frame.style.width = "0px"; frame.style.height = "0px"; frame.style.border = "0px"; } var generateIFrameContent = function() { var frameWindow = window.frames["fileFrame"]; var content = "<form id='frmFile' method='post' enctype='application/data' action='Common/Handler/FileHandler.ashx'><input type='text' id='fileName' name='fileName' /></form>"; frameWindow.document.open(); frameWindow.document.write(content); frameWindow.document.close(); }}\[/code\]In the above example Frame is created only once if same page object is present.And I get the error for the second time while accessing same frame object,Thanks.
 
Back
Top