Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<asp:FileUpload with UpdatePanel

Im trying tp upload more than one image, and when each one I upload I will show it in a repeater, but in the code behind the FileUpload1.HasFile is always False , this is a piece of my code :

  <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true"                                                           UpdateMode="Conditional" >
  <ContentTemplate>
     <asp:Repeater ID="rpUploadedImages" runat="server">
       <ItemTemplate>
        <img src='../Images/<%# DataBinder.Eval(Container.DataItem, "ImagePath")%>'/><br />
       </ItemTemplate>
     </asp:Repeater>
   </ContentTemplate>
   <Triggers>
       <asp:AsyncPostBackTrigger ControlID="btnupload" EventName="click" />
   </Triggers>
 </asp:UpdatePanel>

<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<asp:Button ID="btnupload" runat="server" Text="Upload" onclick="btnupload_Click" />
like image 392
Arrabi Avatar asked Dec 11 '10 13:12

Arrabi


People also ask

How to use FileUpload control with UpdatePanel in asp net?

So the question arises How to use FileUpload Control in UpdatePanel? The answer is by just changing the Trigger of the upload button from AsyncPostBackTrigger to PostBackTrigger. This means that even if the FileUpload control is inside UpdatePanel still there will be a Full Postback when upload button is clicked.

What is the use of UpdatePanel?

UpdatePanel controls are a central part of AJAX functionality in ASP.NET. They are used with the ScriptManager control to enable partial-page rendering. Partial-page rendering reduces the need for synchronous postbacks and complete page updates when only part of the page has to be updated.

What is trigger in UpdatePanel?

Triggers for a given UpdatePanel, by default, automatically include any child controls that invoke a postback, including (for example) TextBox controls that have their AutoPostBack property set to true.


2 Answers

The FileUpload control does not work with UpdatePanel, you will need to do a full post back to get the file on the server... Now there are a lot of tricks to make it ajaxy...

http://geekswithblogs.net/ranganh/archive/2008/04/01/file-upload-in-updatepanel-asp.net-ajax.aspx

like image 135
Jaime Avatar answered Oct 20 '22 01:10

Jaime


Another tricky way is to create iframe with fileupload + submit button(or some trigger) inside your main form. iframe will postback with no effect to main page.

like image 31
Bonshington Avatar answered Oct 20 '22 00:10

Bonshington