Thursday, February 28, 2008

File Upload AJAX V 1.2

As you know that ASP.Net File Upload control can not be placed in multi view. If you put your file upload inside the multi view. You will lost your content when the multi view change the active view.

But the good news is there is Open source control called File Upload Ajax which in V1.2 can be placed inside Wizard, Multi View, invisible Panels, hidden divs, etc.

Download the control @ http://www.codeplex.com/fileuploadajax/Release/ProjectReleases.aspx?ReleaseId=8061

And try this.

  1. Add your FUA in your project
  2. Register in your page or in web.config
  3. <%@ Register Assembly="FUA" Namespace="Subgurim.Controles" TagPrefix="cc1" %>



  4. Add your Update panel, Multiview and file upload



  5. <asp:UpdatePanel ID="up" runat="server">
    <ContentTemplate>
    <asp:MultiView ID="multiPages" runat="server" ActiveViewIndex="0">
    <asp:View ID="v1" runat="server">
    </asp:View>
    <asp:View ID="v2" runat="server">
    upload:
    <cc1:FileUploaderAJAX ID="FileUploaderAJAX1" runat="server" MaxFiles="1" Directory_CreateIfNotExists="true" File_RenameIfAlreadyExists="true"/>
    </asp:View>
    </asp:MultiView>
    </ContentTemplate>
    </asp:UpdatePanel>



  6. Add Code behind code



  7. protected void Page_Load(object sender, EventArgs e)
    {
    if (FileUploaderAJAX1.IsPosting)
    {
    HttpPostedFileAJAX pf = FileUploaderAJAX1.PostedFile;
    FileUploaderAJAX1.SaveAs("~/upload", pf.FileName);
    }
    }


1 comment:

Unknown said...

Not working with update panel. Control do not render properply and Clicking on "add" gives script error "object reference not to set..
any workaround?