【发布时间】:2026-01-21 09:15:01
【问题描述】:
我的页面上有一些更新面板,它们执行一些异步回发以保持正确填充一些下拉列表。我的问题是在我的页面上我有一个处理一些文件上传的 HTML 输入。使用带有异步回发的页面上的 AJAX,当我逐步浏览我的代码时,文件没有被上传。由于我的布局,无法使用回发触发器(非异步)。
这是我的代码:
<div id="divFileInputs" runat="server">
<input id="file1" name="fileInput" type="file" runat="server" size="50" style="width: 50em"
onfocus="AddFileInput()" class="textbox" /></div>
<select id="selectFileList" name="ListBox1" size="5" style="width: 50em; text-align: left;"
class="textbox" />
<input id="RemoveAttachmentButton" type="button" value="Remove" onclick="RemoveFileInput()"
class="removebutton " />
</div>
这是我的代码:
Protected Sub CopyAttachments(ByVal issueId As String)
Dim files As HttpFileCollection = Request.Files
Dim myStream As System.IO.Stream
Dim service As New SubmitService.Service
For i As Integer = 0 To files.Count - 1
Dim postedFile As HttpPostedFile = files(i)
Dim fileNameWithoutPath As String = System.IO.Path.GetFileName(postedFile.FileName)
If fileNameWithoutPath.Length > 0 And issueId.Length > 0 Then
Dim fileLength As Integer = postedFile.ContentLength
Dim fileContents(fileLength) As Byte
' Read the file into the byte array. Send it to the web service.
myStream = postedFile.InputStream
myStream.Read(fileContents, 0, fileLength)
service.ClearQuestAttachToIssue(issueId, fileNameWithoutPath, fileContents)
End If
Next
service = Nothing
End Sub
当我在服务声明处设置断点,然后检查“文件”的值时,计数为 0。当我上传一个文件时,我希望它为 2。
有人知道如何解决这个问题吗?
【问题讨论】:
标签: .net html vb.net ajax input