关于InputFile控件自动弹出选择文件对话框的问题
页面代码如下,页面中点击增加按钮会调用InputFile.click()方法,从而自动打开选择文件对话框。但是选择文件后点击上传按钮时,页面并没有上传,而是把InputFile控件的value清空了。除非这时我再次点击InuptFile的“浏览...“按钮选择文件,之后才能页面提交?有人遇到过这种情况吗?如何解决?
<%@ Page language="c#" Codebehind="test.aspx.cs" AutoEventWireup="false" Inherits="Wind.RPP.Web.test1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>test</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body >
<form id="Form1" method="post" runat="server">
<style> INPUT.btAttach { FONT-SIZE: 9pt; displayx: none } INPUT.buttonA { FONT-SIZE: 9pt } </style>
<script>
var fileCount=0;
function addAttach(obj)
{
var tbl=obj.parentElement.parentElement.parentElement.parentElement;
var tr = tbl.insertRow();
var td=tr.insertCell();
td.noWrap=true;
td.innerHTML='<INPUT id="btAdd" type="button" value="删 除" onclick="delAttach(this)" class="buttonA"><INPUT id="File'+fileCount+'" type="file" name="File'+fileCount+'" size=30 class="btAttach" fileNo="'+fileCount+'" onpropertychangex="showAttachPath(this)"> <span id="FilePath'+fileCount+'"></span>';
var fileNo=fileCount;
fileCount++;
document.all['File'+fileNo].click();
//document.all['WrFileUpload1_File1'].setActive();
//document.all['WrFileUpload1_File1'].click();
//document.all['WrFileUpload1_File1'].defaultValue="C:\\Documents and Settings\\wgduan\\桌面\\新建文件夹\\test.htm"
}
function delAttach(obj)
{
var tr=obj.parentElement.parentElement;
var tbl=obj.parentElement.parentElement.parentElement.parentElement;
tbl.deleteRow(tr.rowIndex);
}
function showAttachPath(obj)
{
if(event.propertyName=='value'){alert(document.all.attachTable.innerHTML);document.all['FilePath'+obj.fileNo].innerText=obj.value;}
}
</script>
<TABLE id="attachTable" cellSpacing="0" cellPadding="3" width="300" border="1" bordercolor="gray" style="FONT-SIZE:10pt;BORDER-COLLAPSE:collapse">
<TR>
<TD noWrap bgcolor="whitesmoke"><INPUT id="btAdd" type="button" value="增 加" onclick="addAttach(this)" class="buttonA" runat="server" NAME="btAdd">上传文件总共不能超过20M
</TD></TR>
<TR>
<TD noWrap>
<INPUT id="btAdd" type="button" value="删 除" onclick="delAttach(this)" class="buttonA" style="VISIBILITY:hidden"><INPUT id="File1" type="file" name="File1" runat="server" size=30 class="btAttach" > </TD>
</TR>
</TABLE><asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</form>
</body>
</HTML>