asp.net 单击按钮时,FileUpload始终返回空值

fnatzsnv  于 2023-11-20  发布在  .NET
关注(0)|答案(1)|浏览(130)

我有这个页面与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

m0rkklqb

m0rkklqb1#

检查你的Page_Load方法,我认为控件在那里被重新初始化了。
如果你在Page_Load中的原始代码是这样的。

Sub Page_Load(..)
Line1 
Line2
...
End Sub

字符串
然后将其更改为以下内容:

Sub Page_Load(..)
    If Not Page.IsPostBack Then     
        'Regular flow, keep the code
        Line1 
        Line2
        ...
    Else 
        'PostBack code, do not reinitialize 
    End If 
End Sub

相关问题