I've got a HTML input in my asp.net page:
<input type="file" name="image" accept="image/*" id="AttachMe">
This is all fine and dandy - it opens the file browse dialog etc.
However, what I would like to do is:
1 - make this invisible (if at all possible - if not I can just move it elsewhere in the page)
2 - trigger this from codebehind
I've got multiple rows in a datalist, each with a button on. The button loads up the relevant bit in C# which finds out which row we've pressed the button on. I then want it to load up the HTML file input.
Unfortunately, I can't simply put the HTML input in each row as we're talking about mobile handsets and space is limited (I tried). Plus I'd like to get the URL of the selected file (I think that's pretty easy to get anyway).
But mainly, I need to know just how to trigger the HTML file input from C# - so I can basically click the button and C# will then trigger the HTML file input for me.
EDIT - this is the code I now have:
My FileUpload:
<asp:FileUpload id="FileUploadControl" runat="server" />
The script to call it:
<script type="text/javascript">
function AttachAFile() {
document.getElementById('<%= FileUploadControl.ClientID %>').click();
}
</script>
This script is called from within the C# codebehind. It is called (I've tried it with alerts and calling other buttons).
However, it's still not calling the FileUploadControl for some reason. Anyone any ideas? I've come across similar topics which all seem to have worked out doing exactly the same as I'm doing (and the FileUploadControl does work on its own).