簡體   English   中英

FileUpload Control無法在“外部” AJAX更新面板中運行,但在具有回發觸發器的“內部”中運行嗎?

[英]FileUpload Control not working 'Outside' AJAX Update Panel but works 'Inside' with Postback trigger?

我的問題是我希望回答的一個簡單問題。

我正在使用一個簡單的文件上傳控件來制作一個簡單的表單,該控件最初並未在AJAX面板中使用,並且對於我一生來說,我無法弄清楚為什么我的代碼(保持不變)找不到FileUpload控件的內容。

<asp:Panel ID="pnlUpload" runat="server" class="workerDetailsPanelLeft" Visible="true">

<h3 class="titleHighlightStyle">Probation Documents</h3><br />
<table cellspacing="0">
<tr>
<td class="standardLabel" valign="top">Current Documents</td>
<td colspan="2">
<asp:ListBox ID="lstDocs" runat="server" Width="200px"></asp:ListBox>
</td>
</tr>
<tr>
<td>
&nbsp;
</td>
<td>
<asp:ImageButton ID="btnSelect" runat="server" SkinID="selectprobationdoc"/>
</td>
<td class="standardLabel" style ="width:200px">Select documents</td>
</tr>
<tr>
<td>
&nbsp;
</td>
</tr>
<tr>
<td class="standardLabel">Upload Documents</td>
<td colspan="2">
<asp:FileUpload ID="uplDoc" runat="server" Height="22px" Width="200px"/> 
</td>
</tr>
<tr>
<td>
&nbsp;
</td>
<td>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" CausesValidation="False" />
</td>
</tr>
<tr>
<td>
&nbsp;
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblUploadError" runat="server" Text="Probation document required" ForeColor="Red" Visible="false"></asp:Label> 
</td>
</tr>
</table>             
</asp:Panel>

原諒我刪除空格的格式化!!

現在,當我的標記是這樣,並且我在FileUpload上調用.HasFile()時,它返回空值嗎?

當我添加以下內容

<asp:UpdatePanel ID="ContentPanel" UpdateMode="Conditional" runat="server" ChildrenAsTriggers="true">
<Triggers>
<asp:PostBackTrigger ControlID="btnSave" />
</Triggers>
<ContentTemplate>
  *Markup as above*

我可以獲取控件的內容。 我了解帶有文件上傳控件的Ajax更新面板存在問題,解決方案是添加回發觸發器,但是誰能從此標記中看到為什么它可能失敗或找不到文件?

            if (this.uplDoc.HasFile)
        {
            String fileExtension = System.IO.Path.GetExtension(uplDoc.FileName).ToLower();
            String validExt = sAllowedExt;

            if (validExt.IndexOf("," + fileExtension + ",") != -1)
            {
                if (this.uplDoc.FileBytes.Length >= 0)
                {
                    return string.Empty;
                }
                else
                {
                    return "PROC0003";  //Invalid File Size            
                }
            }
            else
            {
                return "PROC0002"; //Invalid file type        
            }
        }

上面是檢查后面的初始代碼,此代碼從更新面板開始就沒有改變。

有人可以幫助我了解我錯過了什么嗎?

謝謝

這是一個簡單的答案,

托管內容頁面的母版頁將這些頁面包裝在更新面板中,因此為什么我的代碼未獲取文件上載控件的內容,而是執行異步回發而不是完整回發。

無論如何謝謝@Shai

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM