2017-02-27 60 views
0

我已經通過幾個鏈接,但沒有找到任何有用的信息。我知道這裏已經有好幾次了。FileUpload.hasFile在更新面板內返回false

這裏是我的前端代碼

<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional"> 
      <ContentTemplate> 
     <asp:FileUpload runat="server" ID="fuItemImage" Width="370px" TabIndex="12" /> 
    </ContentTemplate> 
      <Triggers> 

      </Triggers> 
     </asp:UpdatePanel> 

這裏是後端代碼

if (fuItemImage.HasFile) 
    { 
    MyFunction.UploadThisFile(anything) 
    } 

當我上傳任何圖片,並點擊保存按鈕,它顯示了在FileUpload.HasFile假。我被卡住了,並且找不到解決方案。 任何幫助,將不勝感激。

+0

'UpdatePanel'和'FileUpload'不一起工作的文件。 FileUpload需要一個完整的PostBack。如果你想要異步文件上傳,你必須使用別的東西。 – VDWWD

回答

0

你可以試試這個

 <asp:ScriptManager runat="server"></asp:ScriptManager> 
     <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional"> 
      <ContentTemplate> 
     <asp:FileUpload runat="server" ID="fuItemImage" Width="370px" TabIndex="12" /> 
     <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> 

    </ContentTemplate> 
      <Triggers> 
         <asp:PostBackTrigger ControlID = "Button1" /> 

      </Triggers> 
     </asp:UpdatePanel> 

添加按鈕的ID在觸發上傳,這將做回發

+0

這工作,謝謝兄弟。 –

相關問題