FileUpload and UpdatePanel: ScriptManager.RegisterPostBackControl works the second time.
Posted
by VansFannel
on Stack Overflow
See other posts from Stack Overflow
or by VansFannel
Published on 2010-02-15T07:44:30Z
Indexed on
2010/04/30
7:17 UTC
Read the original article
Hit count: 901
Hello.
I'm developing an ASP.NET application with C# and Visual Studio 2008 SP1. I'm using WebForms.
I have an ASPX page with two UpdatePanels, one on the left that holds a TreeView and other on the right where I load dynamically user controls.
One user control, that I used on right panel, has a FileUpload control and a button to save that file on server. The ascx code to save control is:
<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 make a full postback to upload the file to the server and save it to database. But I always getting False on FileUpload.HasFile.
I problem is the right UpdatePanel. I need it to load dynamically the user controls. This panel has three UpdatePanels to load the three user controls that I use.
Maybe I can use an Async File Uploader or delete the right Update Panel and do a full postback to load controls dynamically.
Any advice?
UPDATE:
RegisterPostBackControl
works... the second time I click on save button. First time FileUpload.HasFile is FALSE, and second time is TRUE.
Second Update
On first click I also check ScriptManager.IsInAsyncPostBack and is FALSE. I don't understand ANYTHING!!
Why?
The code to load user control first time, and on each postback is:
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);
}
Thank you.
© Stack Overflow or respective owner