I am creating a upload page in .net. Since the upload controller is very ugly, I want to use a textbox and an image to substituate but still use the upload controller to do the real thing. Here is my code
<script type="text/javascript">
$(document).ready(function() {
$('#browseButton').click(function() {
$('#File1').click();
var fileName = $('#File1').val();
$('#Text1').val(fileName);
});
});
</script>
<div style="display:none"><input type=file id=File1 name=File1 runat="server" /></div>
<input id="Text1" type="text" /><img id="browseButton" src="../images/browse.jpg" style="width: 24px; height: 24px" />
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/upload-eng.gif" onclick="ImageButton1_Click" />
The problem is after I use the “browseButton” to select a file, then I click the image button to do the upload code, it doesn’t work. But if I use the upload controler to choose a file, then I click the image button, everything just works fine. Who knows what’s going on here? Any help is appreciated.
Browsers do not permit you to trigger a file upload dialog programmatically.
If you want pretty uploads, your best bet is likely to be a Flash solution like SWFUpload.