[英]File upload control inside update panel
I have an update panel, in that update panel I have a repeater control and in that repeater control I have file upload control where I am attaching file on each row. 我有一个更新面板,在该更新面板中,我有一个转发器控件,在那个转发器控件中,我有文件上载控件,我在其中将文件附加到每一行上。
I have another update panel, in this I have a save button, whenever I am trying to click this save button and looping through the above mentioned repeater to check file exists in file upload control it always give me false ie the file upload control is cleared. 我有另一个更新面板,在此我有一个保存按钮,每当我尝试单击此保存按钮并遍历上述转发器以检查文件上载控件中是否存在文件时,它总是给我错误,即清除了文件上载控件。
I want to know how can I preserve the file in fileupload control with the existing scenario. 我想知道如何在现有方案中将文件保留在fileupload控件中。
Thank you 谢谢
You need to register the Button for an PostBack. 您需要注册“回发”按钮。 So add a Trigger to the UpdatePanel containing that Button. 因此,将触发器添加到包含该按钮的UpdatePanel。
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
Now you can process the files on the Button click. 现在,您可以在“按钮”单击上处理文件。
protected void Button1_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in Repeater1.Items)
{
FileUpload fu = item.FindControl("FileUpload1") as FileUpload;
if (fu.HasFile)
{
//process file here
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.