目的要实现文件上传。 由于想要在点击一个Button后在页面上弹出OpenFileDialog。但没有好的办法,最终选择了 将FileUpload控件的式样设置为不显示style="display:none",然后通过另一个Button调用Javascript,触发FileUpload的Click()方法,弹出OpenFileDialog。
代码如下: //btnFileSelected触发Test() function Test()
{ document.getElementById("fileOperation").click(); document.getElementById("btnQuery").click();
}
但现在有一个问题,FileUpload控件执行click()后,并没有把选择的文件赋值到FileUpload控件的TextBox上。而且执行到上述代码document.getElementById("btnQuery").click(); 会抛出htmlfile:access denied 异常。
请教各位 这是为什么呢? 有没有更好的办法? btnQuery 是个Button 控件,用于调服务器端代码,操作文件流。 FileUpload不隐藏 也有这个问题。应该跟隐藏没关系。 现在想要实现的是点击一个Button 弹OpenFileDialog 并获取文件流 。
代码如下: //btnFileSelected触发Test() function Test()
{ document.getElementById("fileOperation").click(); document.getElementById("btnQuery").click();
}
但现在有一个问题,FileUpload控件执行click()后,并没有把选择的文件赋值到FileUpload控件的TextBox上。而且执行到上述代码document.getElementById("btnQuery").click(); 会抛出htmlfile:access denied 异常。
请教各位 这是为什么呢? 有没有更好的办法? btnQuery 是个Button 控件,用于调服务器端代码,操作文件流。 FileUpload不隐藏 也有这个问题。应该跟隐藏没关系。 现在想要实现的是点击一个Button 弹OpenFileDialog 并获取文件流 。
类似于163的邮箱,看似点的按惯其实是点的这个file控件.
<input type="file" id="file1" size="1" class="inputfile"
runat="server" />
</a> .fileparent
{
background-image:url(../images/addimg.jpg); background-repeat:no-repeat;
display:block;float:left;height:20px;margin-top:-1px;position:relative;text-decoration:none;top:0pt;width:80px; }
.inputfile
{
cursor:pointer !important; height:18px; left:-13px; filter:alpha(opacity=0); top:1px; width:1px;
}
恩。非常感谢你。