开发者

Can't upload a file with asp:FileUpload

开发者 https://www.devze.com 2023-01-06 05:02 出处:网络
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 th

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> 开发者_StackOverflow中文版
</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>


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

0

精彩评论

暂无评论...
验证码 换一张
取 消