简体   繁体   中英

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.

Thank you

You need to register the Button for an PostBack. So add a Trigger to the UpdatePanel containing that Button.

<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
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM