I am developing an ASP.NET application with C # and Visual Studio 2008 SP1. I am using WebForms.
I have an ASPX page with two UpdatePanels, one on the left that contains the TreeView and the other on the right where I load dynamically user controls.
One user control that I used in the right pane has a FileUpload control and a button for saving this file to the server. Ascx code to save control:
<asp:UpdatePanel ID="UpdatePanelBotons" runat="server" RenderMode="Inline" UpdateMode="Conditional"> <ContentTemplate> <asp:Button ID="Save" runat="server" Text="Guardar" onclick="Save_Click" CssClass="button" /> </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="Save" /> </Triggers> </asp:UpdatePanel>
I am doing a full postback to upload the file to the server and save it to the database. But I always get False on FileUpload.HasFile.
The problem I am is the correct UpdatePanel. I need it to dynamically load user controls. This panel has three updates for loading the three user controls that I use.
Perhaps I can use Async File Uploader or remove the necessary update panel and do a full postback to dynamically load controls.
Any tips?
UPDATE:
RegisterPostBackControl working ... the second time I click the "Save" button. The first time FileUpload.HasFile is FALSE, and the second time is TRUE.
Second update
On the first click, I also check ScriptManager.IsInAsyncPostBack and FALSE. I do not understand anything!
Why?
Code for loading the user control for the first time and for each postback:
DynamicControls.CreateDestination ud = this.LoadControl(ucUrl) as DynamicControls.CreateDestination; if (ud != null) { Button save = ud.FindControl("Save") as Button; if (save != null) ScriptManager1.RegisterPostBackControl(save); PanelDestination.Controls.Add(ud); }
Thanks.
c # file-upload asp.net-ajax updatepanel
Vansfannel
source share