File upload control not working inside update panel

回眸只為那壹抹淺笑 提交于 2019-12-24 05:52:41

问题


I am using the following code to upload the file

<asp:UpdatePanel ID="UpdatePanel18" runat="server">

   <ContentTemplate>

    <asp:FileUpload runat="server" ID="fuImage1" />

    <asp:Button runat="server" ID="btnUpload1" Text="Upload" 
                               onclick="btnUpload1_Click" />
    <asp:ImageButton ID="btnGetImage1" ImageUrl="images/cam.png" Height="25px" 
                        Width="25px" runat="server" onclick="btnGetImage1_Click" />    
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="btnUpload1" />
    </Triggers> 
</asp:UpdatePanel>

When i select a file to upload, path is not getting displayed on the file upload control. Need help to fix this problem


回答1:


This is a frustrating feature of the update panel. Give this post a read which goes over the cause of this issue as well as a resolution:

http://geekswithblogs.net/mmintoff/archive/2009/04/01/fileupload-within-updatepanel.aspx




回答2:


This should work

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
            <Triggers>
                <asp:PostBackTrigger ControlID="Button1" />
            </Triggers>
            <ContentTemplate>
                 <asp:FileUpload ID="FileUpload1" runat="server" />
                 <asp:Button ID="Button1" runat="server"Text="Upload" OnClick="Button1_Click" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>


来源:https://stackoverflow.com/questions/5916554/file-upload-control-not-working-inside-update-panel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!