我有这个带有 FileUpload 元素的页面。但是当我尝试获取后面代码中的值时,它总是返回“NULL”值。它只发生在一页中。其他页面完美运行。似乎有什么问题?我尝试搜索但没有任何效果。比如使用 UpdatePanel、触发器等
下面是我的代码:
ASPX
<telerik:RadWindow ID="showImportDialog" runat="server" Skin="<%$ appSettings:Skin %>" EnableEmbeddedSkins="false"
Width="350" Height="200" Behaviors="Close" Modal="true" VisibleTitlebar="true" Title="<%$ Resources:Master, Import%>">
<ContentTemplate>
<div class="inputField">
<p style="font-weight: bold; padding-bottom: 3px;"><asp:Literal runat="server" Text="<%$ Resources:Master, SelectImportFileLbl %>" /></p>
<div class="uploadFile">
<span class="glyphicon glyphicon-import"></span>
<span class="filename fontSize13"><asp:Literal runat="server" Text="<%$ Resources:Master, ImportFieldText %>" /></span>
<asp:FileUpload ID="ImportFile" runat="server" CssClass="fontSize13" ClientIDMode="static"/>
</div>
<p id="errorMsg" style="color: #FF0000; font-size:11px; display: none; padding-bottom: 5px; padding-top: 5px;">
<asp:Label ID="Label5" ClientIDMode="static" runat="server" Text=""/>
</p>
</div>
<div id="importGroup" class="delete-confirm-button" style="padding-top: 20px;">
<asp:Button ID="BtnImport" runat="server" AutoPostBack="false" enabled="false"
EnableEmbeddedSkins="false"
Text="<%$ Resources:Master, Import %>" ClientIDMode="static" />
<asp:Button ID="BtnImportCancel" runat="server" AutoPostBack="false" enabled="true"
EnableEmbeddedSkins="false" OnClientClick="btnCancel_Click('showImportDialog'); return false;"
Text="<%$ Resources:Master, Cancel %>" ClientIDMode="static" />
</div>
</ContentTemplate>
</telerik:RadWindow>
VB
Protected Sub BtnImport_Click(sender As Object, ByVal e As EventArgs) Handles BtnImport.Click
Dim fileName As String = String.Concat(Path.GetFileNameWithoutExtension(ImportFile.PostedFile.FileName), "_", DateTime.Now.ToString("HHmmssff"), ".", Path.GetExtension(ImportFile.PostedFile.FileName))
Dim filePath As String = System.IO.Path.Combine("DataImport", fileName)
Dim fInfo As System.IO.FileInfo = New System.IO.FileInfo(filePath)
fInfo.Directory.Create()
ImportFile.SaveAs(filePath)
End Sub
检查你的
Page_Load
方法,我认为控件正在那里重新初始化。将不想重新初始化的代码用 If Not Page.IsPostBack Then
括起来