UpdatePanel and FileUpload

Last post 05-21-2008 7:09 AM by phsika. 6 replies.

Sort Posts:

  • UpdatePanel and FileUpload

    07-17-2007, 6:02 AM
    • Member
      50 point Member
    • Faber75
    • Member since 01-10-2007, 2:32 PM
    • Posts 32

    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

  • Re: UpdatePanel and FileUpload

    07-17-2007, 7:26 AM
    Answer

    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>

    DC517
    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved.
  • Re: UpdatePanel and FileUpload

    07-17-2007, 9:04 AM
    • Member
      50 point Member
    • Faber75
    • Member since 01-10-2007, 2:32 PM
    • Posts 32

    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

  • Re: UpdatePanel and FileUpload

    07-30-2007, 7:28 PM
    • Member
      12 point Member
    • firewire1981
    • Member since 06-01-2007, 4:18 PM
    • Posts 9
    Thank you! I've been fighting with this for a week!
  • Re: UpdatePanel and FileUpload

    12-04-2007, 4:15 AM
    • Member
      351 point Member
    • Petrander
    • Member since 10-31-2005, 3:13 PM
    • Copenhagen
    • Posts 122
    Thanks for the tip!!!!
  • Re: UpdatePanel and FileUpload

    03-11-2008, 4:30 PM
    • Member
      112 point Member
    • bassrocks
    • Member since 06-22-2006, 5:45 PM
    • Gloucester, MA, USA
    • Posts 48

    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

  • Re: UpdatePanel and FileUpload

    05-21-2008, 7:09 AM
    • Member
      29 point Member
    • phsika
    • Member since 02-03-2008, 3:22 AM
    • turkey
    • Posts 28

    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; position: absolute; 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;

    position: absolute; top: 484px" />

    &nbsp;

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

    height: 33px">

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

    </div>

     

     

    </div>

    </form>

    </body>

    </html>

    www.ykaratoprak.blogspot.com
Page 1 of 1 (7 items)