views:

505

answers:

1

I have the following code, and I can't get the UpdatePanel to Update. Any ideas? I'm wondering if its possible to do a Update from within async method?

<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
              <ContentTemplate>
                 <asp:DataGrid ID="dgFiles" runat="server" DataKeyField="ConfigurationFileId" AutoGenerateColumns="false" GridLines="None" 
                 OnItemCommand="dgFiles_ItemCommand" Width="40%">
                <Columns>
                    <asp:TemplateColumn>
                        <ItemTemplate>
                            <asp:Label ID="lblFile" runat="server" Text='<%#Eval("SourceFileName") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn>
                        <ItemTemplate>
                            <asp:LinkButton ID="hypDelete" runat="server" Text="Delete" CssClass="blue" CommandName="Delete" CommandArgument="5"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                </Columns>
               </asp:DataGrid>
              </ContentTemplate>
           </asp:UpdatePanel>
           <asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
              <ContentTemplate>
                 <ajaxToolkit:AsyncFileUpload ID="Upload1" runat="server" UploaderStyle="Modern" Width="400px"
                     Style="visibility: hidden" OnUploadedComplete="Upload1_Complete" OnClientUploadComplete="UploadComplete" />

                 <asp:DataGrid ID="dgAddFiles" runat="server" DataKeyField="ConfigurationFileId" AutoGenerateColumns="false"
                    Width="40%" Style="visibility: hidden">
                       <Columns>
                          <asp:TemplateColumn>
                             <ItemTemplate>
                                <asp:Label ID="lblFile" runat="server" Text='<%#Eval("SourceFileName") %>'></asp:Label>
                             </ItemTemplate>
                          </asp:TemplateColumn>
                          <asp:TemplateColumn>
                             <ItemTemplate>
                                <asp:LinkButton ID="hypDelete" runat="server" Text="Delete" CssClass="blue" CommandName="Delete" CommandArgument="5"></asp:LinkButton>
                             </ItemTemplate>
                          </asp:TemplateColumn>
                       </Columns>
                    </asp:DataGrid>
              </ContentTemplate>
           </asp:UpdatePanel>




 protected void Upload1_Complete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
  {
     if (Upload1.HasFile)
     {
        Upload1.SaveAs(Server.MapPath("~/files/temp/") + Upload1.FileName);
        byte[] data = Upload1.FileBytes;
        var file = new Files();
        file.FileId = Guid.NewGuid();
        file.FileName = Upload1.FileName;
        file.Data = data;

        using (var ctx = new DeviceManagerEntities())
        {
           ctx.AddToFiles(file);

           ctx.SaveChanges();

           var files = ctx.Files
              .ToList();
           dgAddFiles.DataSource = files;
           dgAddFiles.DataBind();
           UpdatePanel3.Update();
        }
     }
  }
+1  A: 

Read this (Credit to Schelfaut.NET) and see if it solves your situation:

thedugas