Saeed ur Rehman Saeed ur Rehman -4 years ago 129
ASP.NET (C#) Question

FileUpload.hasFile returning false inside update panel

I have been through several links but didn't find anything helpful. I know it has been asked several times here.

Here is my frontend code

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

</Triggers>
</asp:UpdatePanel>


Here is the backend code

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


When I upload any image and click on the save button it shows false in FileUpload.HasFile. I am stuck and finding no solution for it.
Any help would be appreciated.

Answer Source

you can try this

        <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>

add the button id in triggers to upload the file which will do postback

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download