文件上传和的UpdatePanel:ScriptManager.RegisterPostBackControl工作第二次 [英] FileUpload and UpdatePanel: ScriptManager.RegisterPostBackControl works the second time
问题描述
我正在开发用C#和Visual Studio 2008 SP1的ASP.NET应用程序。我使用的WebForms。
I'm developing an ASP.NET application with C# and Visual Studio 2008 SP1. I'm using WebForms.
我有两个UpdatePanel的,一个是关于持有在哪里我动态加载用户控件权的TreeView和其他左侧有一个ASPX页面。
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.
一个用户控制,我右边的面板上使用,有一个FileUpload控件和一个按钮,以节省服务器的文件。该ASCX code,以节省控制:
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>
我做一个完整的回发到上传文件到服务器上,并保存到数据库中。但是,我总是在FileUpload.HasFile越来越假。
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.
我的问题是正确的UpdatePanel。我需要它来动态加载用户控件。此面板有三个UpdatePanel的加载,我用三个用户控件。
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.
有什么建议?
更新:
RegisterPostBackControl
工作 ...我第二次点击Save按钮。第一次FileUpload.HasFile为FALSE,且第二次是真。
RegisterPostBackControl
works... the second time I click on save button. First time FileUpload.HasFile is FALSE, and second time is TRUE.
第二次修订
首先点击我还要检查ScriptManager.IsInAsyncPostBack是FALSE。我什么都不懂!
Second Update
On first click I also check ScriptManager.IsInAsyncPostBack and is FALSE. I don't understand ANYTHING!!
为什么?
在code加载用户控件第一次,在每次回发是:
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);
}
感谢您。
推荐答案
对于我这个解决方案工作:
For me this solution worked:
添加
Page.Form.Attributes.Add(ENCTYPE,多部分/表单数据);
add Page.Form.Attributes.Add("enctype", "multipart/form-data");
该enctype属性上缺少第一回发。
The enctype attribute is missing on the first postback.
<一个href=\"http://adamnoffie.blogspot.com/2007/10/file-upload-not-working-on-first.html\">http://adamnoffie.blogspot.com/2007/10/file-upload-not-working-on-first.html
这篇关于文件上传和的UpdatePanel:ScriptManager.RegisterPostBackControl工作第二次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!