Tuesday, November 5, 2013

How to include FileUpload Control into Update Panel in Asp.Net

Hi,

We all encounter this problem in our applications. we might get into a situation like whole content of page should be in update panels and a FileUpload control is required in that page.

Here,we should sacrifice a update panel to work with FileUpload control.

To get rid off this mess, we can follow below solution.

Observe below code:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:FileUpload ID="FileUpload1" runat="server" />
         <asp:Button ID="btnUpload" runat="server" Text="Upload"
           OnClick = "btnUpload_Click" />               
    </ContentTemplate>
    <Triggers>
           <asp:PostBackTrigger ControlID = "btnUpload" />
    </Triggers>
</asp:UpdatePanel>

Here, FileUpload control and upload button are in a update panel

Everything is same except a Trigger.

This Trigger(PostBackTrigger) makes difference for us.Even though Fileupload control is in update panel,on clicking upload button post back occurs(so that our fileupload will work and rest of the controls will be in update panel as we desired.)

Thanks and Regards,
Hari

No comments:

Post a Comment