try to set the width to 0 and display a readonly textbox, for example<form runat="server" enctype="multipart/form-data">
<input type="text" name="txt1" readonly>
<input type="file" id="file1" runat="server" style="width:0;border-width:0;" onpropertychange="this.form.txt1.value=this.value">
<asp:Button runat=server Text="submit" OnClick="SubmitForm"/>
</form>
<script language="C#" runat="server">
void SubmitForm(Object sender, EventArgs e)
{
if (file1.PostedFile.FileName != String.Empty && file1.PostedFile.ContentLength > 0)
{
Response.Write(String.Format("{0} is upload,size of {1}", file1.PostedFile.FileName, file1.PostedFile.ContentLength ));
}
}
</script>>>>用什么语句判断输入框里是否为空 on the client, you can use inputFile.value to check, on the server side, check FileName and ContentLength
<input type="text" name="txt1" readonly>
<input type="file" id="file1" runat="server" style="width:0;border-width:0;" onpropertychange="this.form.txt1.value=this.value">
<asp:Button runat=server Text="submit" OnClick="SubmitForm"/>
</form>
<script language="C#" runat="server">
void SubmitForm(Object sender, EventArgs e)
{
if (file1.PostedFile.FileName != String.Empty && file1.PostedFile.ContentLength > 0)
{
Response.Write(String.Format("{0} is upload,size of {1}", file1.PostedFile.FileName, file1.PostedFile.ContentLength ));
}
}
</script>>>>用什么语句判断输入框里是否为空 on the client, you can use inputFile.value to check, on the server side, check FileName and ContentLength
if(flFile.Value.Trim() != "")
{
if(flFile.PostedFile == null) //验证文件是否有效的文件
{
this.RegisterStartupScript("jsSelFile","<script language=javascript>alert('请正确选择您要上传的文件!')</script>");
return;
}
else
{
//你的上传代码。
}
}