locked
UpdatePanel and FileUpload RRS feed

  • Question

  • User499615865 posted

    Hi,

    i have wide customer table that i handle with a big DetailView nested inside an UpdatePanel for faster interaction. Works like a charm.

    Now they ask me to allow the user to upload a file, but when i add it in the detail view and i save data i get no file at all, as if putting it into an updatepanel do not allow him to send the file any more.

    Is there some setting i have to put so to make it work ?

    thanks in advance,

    Fabrizio

    Tuesday, July 17, 2007 6:02 AM

Answers

  • User-989915499 posted

    Hi There,

    This is a known ** not sure should call it issue, but callback will not work for FileUpload ( e.g. have fileupload in updatepanel )

    The trick is assign postbacktrigger to the button that upload the file.

    Example:

    <asp:ScriptManager ID="ScriptManager1" runat="server">

    </asp:ScriptManager>

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

    <Triggers>

    <asp:PostBackTrigger ControlID="Button1" />

    </Triggers>

    <ContentTemplate>

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

    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

    </ContentTemplate>

    </asp:UpdatePanel>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 17, 2007 7:26 AM

All replies

  • User-989915499 posted

    Hi There,

    This is a known ** not sure should call it issue, but callback will not work for FileUpload ( e.g. have fileupload in updatepanel )

    The trick is assign postbacktrigger to the button that upload the file.

    Example:

    <asp:ScriptManager ID="ScriptManager1" runat="server">

    </asp:ScriptManager>

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

    <Triggers>

    <asp:PostBackTrigger ControlID="Button1" />

    </Triggers>

    <ContentTemplate>

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

    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

    </ContentTemplate>

    </asp:UpdatePanel>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 17, 2007 7:26 AM
  • User499615865 posted

    Hi,

    Thanks for your help, after posting i found other posts on the problem, for future references i add here another help to the problem of the button not sending the file on the first click.

    try to use this

    in Form tag add this

    enctype="multipart/form-data"

    example: 

    <form id="form1" enctype="multipart/form-data" runat="server">

     i use that and it works
     

    As in http://forums.asp.net/t/1060363.aspx?PageIndex=2

    Tuesday, July 17, 2007 9:04 AM
  • User139771134 posted
    Thank you! I've been fighting with this for a week!
    Monday, July 30, 2007 7:28 PM
  • User521627780 posted
    Thanks for the tip!!!!
    Tuesday, December 4, 2007 4:15 AM
  • User1960767503 posted

    Great solution, but is it possible to make it work within nested update panels? I tried adding the PostBackTrigger to both panels -- no errors, but it didn't work.

    Thanks,
     Andy

    Tuesday, March 11, 2008 4:30 PM
  • User-2071681944 posted

    i have tabcontrol update panel and fileupload and send button  on tab control . But it doesn't work. if i choose a image browse and click send button, it won't work.

    C# codes:

    protected void Page_Load(object sender, EventArgs e)

    {

    }

    protected void Button1_Click(object sender, EventArgs e)

    {

    if (FileUpload1.HasFile)

    {

    FileUpload1.SaveAs(Server.MapPath(
    "~\\resimler\\" + FileUpload1.FileName));

    }

    }

    protected void Button2_Click(object sender, EventArgs e)

    {

    if (FileUpload2.HasFile)

    {

    FileUpload2.SaveAs(Server.MapPath(
    @"resimler\" + FileUpload2.FileName));

    }

    }

    }

     

    SOURCE:

     

    <form id="form1" runat="server">

    <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" />

    <div>

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

    <ContentTemplate>

    <ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0" Height="295px"

    Style="z-index: 26; left: 100px; ; top: 50px" Width="771px" >

    <ajaxToolkit:TabPanel ID="TabPanel1" runat="server" HeaderText="Resim G&#246;nder" Width="120px" Height="120px" ScrollBars="Both" BackColor="Azure">

     

    <HeaderTemplate>

    <asp:Label ID="Label1" runat="server" Text="Resim Göster" BackColor="blue" ForeColor="white"></asp:Label>

    </HeaderTemplate>

     

    <ContentTemplate>

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

    <asp:Button ID="Button1" runat="server" Style="z-index: 100; left: 32px;

    top: 144px" Text="Yolla" OnClick="Button1_Click" />

    </ContentTemplate>

     

     

    </ajaxToolkit:TabPanel>

     

    </ajaxToolkit:TabContainer>

    </ContentTemplate>

    <Triggers>

    <asp:AsyncPostBackTrigger ControlID="Button1" />

    </Triggers>

    </asp:UpdatePanel>

    <asp:FileUpload ID="FileUpload2" runat="server" Style="z-index: 100; left: 14px;

    ; top: 484px" />

    &nbsp;

    <div style="z-index: 101; left: 261px; width: 100px; ; top: 479px;

    height: 33px">

    <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Yolla" />

    </div>

     

     

    </div>

    </form>

    </body>

    </html>

    Wednesday, May 21, 2008 7:09 AM
  • User-654491737 posted

    Gr8 thing. It Saved a lot of time. Thanks a lot.

    Friday, February 19, 2010 8:16 AM
  • User-654491737 posted

    Hi,

      By using the triggers, it solved my problem only partially. The main problem is i want to avoid the page to be posted back when the button in the ModalPopupextender is clicked, i.e i want only asynchronous post back of the control. Do u have a solution for this problem.


    Tuesday, February 23, 2010 12:01 AM
  • User2058447048 posted

    @phsika -The reason it is not working is because the Upload control is not inside the UpdatePanel. Check your code again. 

     

    My only problem here is that after evaluating my form and found a problem in some other controls, the upload's file is gone once the page refreshes. Now, I have to re-upload it but the problem is the file is already in the server. I don't want him to choose a file on the server and use it for his own purpose - I am trying to control the uploads and monitor who uploaded each file.

    If only there is a command on the Page_load saying don't refresh this control :(

    Tuesday, July 6, 2010 6:21 AM
  • User854758153 posted

    Hi,

    Thanks for your help, after posting i found other posts on the problem, for future references i add here another help to the problem of the button not sending the file on the first click.

    try to use this

    in Form tag add this

    enctype="multipart/form-data"

    example: 

    <form id="form1" enctype="multipart/form-data" runat="server">

     i use that and it works
     

    As in http://forums.asp.net/t/1060363.aspx?PageIndex=2

    thanks...!!

    Thursday, September 2, 2010 9:47 AM
  • User-1272177930 posted

    Thanks! Ading this below:

    <Triggers>

    <asp:PostBackTrigger ControlID="Button1" />

    </Triggers> 

    to my updatepanel worked for me. Though I also added  enctype="multipart/form-data" to my form in the masterpage.

    <form id="form1" enctype="multipart/form-data" runat="server" >

    Tuesday, October 29, 2013 10:45 PM