为什么上传按钮不起作用?
我正在 .net 中创建一个上传页面。由于上传控制器非常丑陋,我想使用文本框和图像来代替,但仍然使用上传控制器来做真正的事情。这是我的代码
<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" />
问题是在我使用“browseButton”选择文件后,然后单击图像按钮执行上传代码,它不起作用。但是,如果我使用上传控制器选择一个文件,然后单击图像按钮,一切都会正常工作。谁知道这里发生了什么事?任何帮助表示赞赏。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
浏览器不允许您以编程方式触发文件上传对话框。
如果您想要漂亮的上传,最好的选择可能是像 SWFUpload 这样的 Flash 解决方案。
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.