Afzaal
Afzaal

Reputation: 9

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 i.e 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

Upvotes: 0

Views: 2225

Answers (1)

VDWWD
VDWWD

Reputation: 35514

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

Upvotes: 3

Related Questions