单击上传按钮后清除Fileupload [英] Fileupload clear after clicking upload button

查看:80
本文介绍了单击上传按钮后清除Fileupload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用文件Fileupload asp.net控件上传文件,浏览文件后

当我点击上传按钮时它会清除所选文件。



我尝试过:







< asp:FileUpload ID =FileUpload1runat =server/>





< asp:Button ID = Button1runat =serverText =UploadCausesValidation =false/>









代码背后,

受保护的子Button1_Click(发件人为对象,e为EventArgs)处理Button1.Click

If(FileUpload1。 HasFile)然后

DtTable3 =会话(DtTable3)

Dim Fi leName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)

FileName = txtCustItemCode.Text + FileName

每个drRow In DtTable3.Rows

如果修剪(drRow(Filename))= FileName则

uscMsgBox1.AddMessage(Trim(FileName)& 此文件已存在,UserControls_uscMessageBox.enmMessageType.Error)

退出Sub

结束如果

下一页

Dim Extension As String = Path.GetExtension(FileUpload1.PostedFile.FileName)

Dim FolderPath As String = ConfigurationManager.AppSettings(FolderPath)

Dim FilePath As String = Server.MapPath(FolderPath + FileName)

FileUpload1.SaveAs(FilePath)

drRow = DtTable3.NewRow

drRow.Item(Filename )= FileName

drRow.Item(FilePath)= FilePath

DtTable3.Rows.Add(drRow)

Session(DtTable3) )= DtTable3



否则

uscMsgBox1.AddMessage(在浏览按钮上选择文件cilck,UserControls_uscMessageBox.enmMessageType.Info)

结束如果

End Sub

运行后,它将始终提供以下输出:

选择文件cilck on browse按钮。

I am using file Fileupload asp.net control for uploading file ,after browsing files
when I'll click upload button it clears the selected file.

What I have tried:



<asp:FileUpload ID="FileUpload1" runat="server" />


<asp:Button ID="Button1" runat="server" Text="Upload" CausesValidation="false" />




In code Behind,
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If (FileUpload1.HasFile) Then
DtTable3 = Session("DtTable3")
Dim FileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
FileName = txtCustItemCode.Text + FileName
For Each drRow In DtTable3.Rows
If Trim(drRow("Filename")) = FileName Then
uscMsgBox1.AddMessage(Trim(FileName) & "This File is already exist", UserControls_uscMessageBox.enmMessageType.Error)
Exit Sub
End If
Next
Dim Extension As String = Path.GetExtension(FileUpload1.PostedFile.FileName)
Dim FolderPath As String = ConfigurationManager.AppSettings("FolderPath")
Dim FilePath As String = Server.MapPath(FolderPath + FileName)
FileUpload1.SaveAs(FilePath)
drRow = DtTable3.NewRow
drRow.Item("Filename") = FileName
drRow.Item("FilePath") = FilePath
DtTable3.Rows.Add(drRow)
Session("DtTable3") = DtTable3

Else
uscMsgBox1.AddMessage("Select File cilck on browse button", UserControls_uscMessageBox.enmMessageType.Info)
End If
End Sub
After running it will give output as following always :
Select File cilck on browse button.

推荐答案

它执行此操作出于安全考虑,没有办法绕过它。
It does this for security reasons, there is no way to get around it.


我使用< triggers>在更新面板&内容模板以外的工作

< triggers>

< asp:PostBackTrigger ControlID =Button1>
I use <triggers> in update panel & outside of content Template its work
<triggers>
<asp:PostBackTrigger ControlID="Button1">


这篇关于单击上传按钮后清除Fileupload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆