3
votes

I have asp.net webforms page with Fileupload control and image. When user clicks on image I trigger FileUpload click and when clicking ok I call __doPostBack on client side. If FileUpload is visible it works fine, but when I set style='visibility: hidden' or display: none - javascript gives error: access denied! It reproduces only in IE, not FF or chrome. Could anybody tell me how to avoid this and post the file to server? I have tried input type='file' with runat='server', non-server input-file - the result is the same...

HTML:

<input id="_ctl00_fuplImage" type="file" style="visibility: hidden" name="$ctl00$fuplImage">

JavaScript:

var fileupload = $('#<%= fuplImage.ClientID %>');

$('#<%= imgPhoto.ClientID %>').click(function() {
    fileupload.click();
});

fileupload.change(function() {
    var val = fileupload.val();
    if (val == '') return;
    __doPostBack(fileupload.attr('id'), val);
});
1
Can you post the generated HTML source code for that FileUpload control? - Šime Vidas
<input id="_ctl00_fuplImage" type="file" style="visibility: hidden" name="$ctl00$fuplImage"> ... - idm
How do you trigger the FileUpload click? It seems that some sort of security mechanism prevents you from triggering clicks on hidden file-fields. - Šime Vidas
var fileupload = $('#<%= fuplImage.ClientID %>'); $('#<%= imgPhoto.ClientID %>').click(function () { fileupload.click(); }); fileupload.change(function () { var val = fileupload.val(); if (val == '') return; __doPostBack(fileupload.attr('id'), val); }); - idm
I was not able to reproduce your issue. Live demo: jsfiddle.net/NjgDR/3 I've tested this demo in IE7, IE8, and IE9. When I click the image, the "Choose file" window pops up normally. No "access denied" error is thrown. - Šime Vidas

1 Answers

4
votes

It is unresolvable security issue of IE (only) that does not allow to send form with hidden file upload input. Thank you very much for your help.