views:

37

answers:

1

Hi,

For some reason, I'm unable to upload a file with the <asp:FileUpload /> control. I know it's not just something completely pooched, because I created a new project with this code in it and that uploaded the file.

My code looks like this (some bits removed...):

<form id="querydata" runat="server" enctype="multipart/form-data">
        <div class="container" runat="server">
        <asp:ScriptManager ID="queryscriptmanager" runat="server" />
        <asp:UpdatePanel runat="server" ID="querypanel" UpdateMode="Conditional">
        <ContentTemplate>
        <div runat="server" class="opaque" id="opq">
                <div runat="server" class="entry">
                    <asp:FileUpload runat="server" ID="Directory" Width="194" />
                </div>
               <asp:Button runat="server" ID="Submit" Text="Update Database" onclick="checkForm"  />
        </div>
        </ContentTemplate>
        </asp:UpdatePanel>
        </div> 
</form>

If I go select a file, then click the submit button, once the execution makes it to checkForm, Directory.FileName is "" and Directory.HasFile is False

Any clue why it won't send my file?


SOLVED:
All I had to do (per the blog post in the accepted answer) was add three lines:

</ContentTemplate>

<Triggers>
   <asp:PostBackTrigger ControlID="Submit" />
</Triggers>

</asp:UpdatePanel>

+3  A: 

The problem is the UpdatePanel. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx#using_the_FileUpload_Control_with_the_UpdatePanel_control.

An excellent blog post that will help you fix it: http://geekswithblogs.net/mmintoff/archive/2009/04/01/fileupload-within-updatepanel.aspx

matt-dot-net
Success! The trigger event made it work perfectly, thank you!
Wayne Werner