简体   繁体   English

更新面板中的文件上传控件

[英]File upload control inside update panel

  1. 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. 我有一个更新面板,在该更新面板中,我有一个转发器控件,在那个转发器控件中,我有文件上载控件,我在其中将文件附加到每一行上。

  2. 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.

相关问题 带有文件上传的更新面板 - update panel with file upload 更新面板中的文件上载控件始终返回false - File Upload control in update Panel Always returns false 更新面板内的异步文件上传和触发回发的下拉菜单不起作用 - Asynchronous file upload inside a update panel and a dropdown to trigger postback not working 服务器控件中的“更新”面板 - Update panel inside Server Control uplodify上传(文件上传)在更新面板中不起作用? - uplodify upload (File Upload) is not working in Update Panel? HTML输入文件控件在更新面板中使用时不上传文件 - Html input file control doesn't upload file when used in update panel 在更新面板中的文件上传控件中丢失文件 c# asp.net - Losing file in a file upload control in update panel c# asp.net 在更新面板中显示带有文件上传的进度更新 - Show Progress Update with File Upload in Update Panel 异步实现文件上传控制时,UpdateProgress和触发器部分在“更新”面板中不起作用 - UpdateProgress and trigger section not working in Update panel while implement file upload control asynchronously ASP.NET C#更新面板,文件上载控制以及回发时维护和保存信息 - ASP.NET C# Update Panel, File Upload Control and maintaining and saving information on postback
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM