0

I develop custom file uploader.

<asp:FileUpload runat="server" ID="fuUpload" />

<asp:UpdatePanel  runat="server" >
    <ContentTemplate>
     <asp:Button ID="btnUpload" runat="server" Text="Upload" CausesValidation="false"
            OnClick="btnUpload_Click" />

      <div>
        <asp:Label ID="lblError" runat="server" Visible="false" ForeColor="Red" /></div>
        <asp:Repeater ID="rptAttachments" runat="server" OnItemCommand="Uploader_ItemCommand">
            <ItemTemplate>
                <div>
                    <a href='<%#GetUrl(....) %>'><%#Eval("Filename") %></a> <b>
                   <asp:LinkButton ID="lnkDelete" runat="server" Text="Удалить" CommandName="DeleteAttachment" CommandArgument='<%#Eval("FileName") %>' /></b>
                </div>
            </ItemTemplate>
        </asp:Repeater>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnUpload" EventName="Click" />
        <asp:AsyncPostBackTrigger ControlID="rptAttachments" EventName="ItemCommand" />
    </Triggers>
</asp:UpdatePanel>




 protected void btnUpload_Click(object sender, EventArgs e)
  {          
   //fuUpload.HasFile == false 
    if (fuUpload.HasFile && fuUpload.PostedFile != null 
        && fuUpload.PostedFile.ContentLength > 0)
     { 
     }
  }

I wonder why fuUpload.HasFile always equls null.

1
  • naveen's solution is good. The reason for the full postback is that the fileupload does NOT work with asynchronous postbacks. Commented Jul 20, 2011 at 6:12

1 Answer 1

2

Try these things.

  1. Put <asp:FileUpload runat="server" ID="fuUpload" /> inside UpdatePanel
  2. Set btnUpload trigger like this. <asp:PostBackTrigger ControlID="btnUpload" />
Sign up to request clarification or add additional context in comments.

2 Comments

It works with postback! Could I use fileUpload without postBack?
there are no simple methods to do so. but you can always use something like jQuery Ajax uploader plugin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.