FileUpload in FormView inside an UpdatePanel

asp.netfile uploadformviewpostbackupdatepanel

The Scenario:
I have an ASP.Net webpage which I intend to use for letting the user(not the real users, but content manager basically) insert and edit the records in a table using a FormView. This FormView is inside an UpdatePanel, as I'm also using cascading dropdownlists to let the user select some values.

Now, this FormView also contains 4 FileUpload controls, and as you might know that these fileupload controls require a full postback since most browsers do not let Javascript access the disk. So, this problem would have been solved by doing something like:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
           <Triggers>
           <asp:PostBackTrigger ControlID="InsertButton" />
           <asp:PostBackTrigger ControlID="UpdateButton" />
           </Triggers>
                    <ContentTemplate>....</ContentTemplate>
</asp:UpdatePanel>

Edit: Forgot to add that the fileuploading takes place in the OnUpdating and OnInserting events of the SqlDataSource.

The Problem:
Since the InsertButton and the UpdateButton reside inside the Formview, I cannot directly access their ID's through markup. And MSDN says that:

Programmatically adding
PostBackTrigger controls is not
supported.

Please suggest some solution to make this work. Any insight on the matter is highly appreciated. Thanks.

P.S.- A workable solution for me was to set the UpdatePanel's PostBackTrigger as the whole FormView itself:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
           <Triggers>
           <asp:PostBackTrigger ControlID="FormView1" />
           </Triggers>
                    <ContentTemplate>....</ContentTemplate>
</asp:UpdatePanel>

But now due to a bit of change in requirements, this solution(if you call it a solution) is not acceptable.

Best Answer

Have you given a though about using Iframe for doing the postback ? something like:

<iframe name="uploader" id=uploader 
          src="uploaderSender.aspx?AllowedExtension=<%= AllowedExtension %>&StoringPath=<%= StoringPath %>&StoringFileName=<%= StoringFileName %>&OldFileName=<%= OldFileName %>&MaximumSize=<%= MaximumSize %>"
         width="450" height="50" frameborder=0  scrolling=no >
        </iframe>

with uploaderSender.aspx like :

<form action="UploaderReceiver.aspx" method="post"  enctype="multipart/form-data">
 <input type="file" name="file" id="file"  onchange="document.getElementById('IsFileUploading').style.visibility = 'visible'; document.forms[0].submit()"/>

    <span id="IsFileUploading" style="visibility: hidden">
        <asp:Image ID="Image1" runat="server" ImageUrl="~/immagini/Ajax-loader.gif" />
    </span>
</form>

and UploaderReceiver.aspx like :

protected void Page_Load(object sender, EventArgs e)
        {

            //if there is one file to process
            if (Request.Files.Count > 0)
                //create the folder if it does'nt exists and returns the local path to get it
                string StoringPathToBeSaved = StoringPath.GetFolderPath();

                // append the name of the file to upload to the path.
                            StoringPathToBeSaved = StoringPathToBeSaved + StoringFileName + Extension;

                            Request.Files[0].SaveAs(StoringPathToBeSaved);

        }

this is just bits of code just for you to figure out if you would be interested in this way of dealing with the upload, I can give you more if you want after.

see you, and good luck with your code,