Iterating a dynamic collection of FileUpload controls in a control panel using ASP.NET C #

I am trying to get the values ​​of dynamically created FileUpload controls that I add to the Panel:

<asp:Panel ID="pFileControls" runat="server">
</asp:Panel>

I create controls during a loop through a set of records:

foreach(DataRow dr in ds.Tables[0].Rows)
{
    FileUpload fu = new FileUpload();
    fu.ID = dr["SomeID"].ToString();

    pFileControls.Controls.Add(fu);
}

Everything works fine until I submit the form using this button:

<asp:Button ID="btnImportFile" runat="server" Text="Save" OnClick="btnImportFile_Click" />

What I am registering as this (Page_Load):

ScriptManager.GetCurrent(this).RegisterPostBackControl(btnImportFile);

I do this because I use the MasterPage / ContentPage parameter on my website, and basically everything happens inside the UpdatePanel for AJAXification purposes. Keep in mind that if I explain, specify the FileUpload control in the HTML view, it works 100%.

When the form is submitted, I try to iterate the panel as follows:

foreach (Control ctrl in pFileControls.Controls)
{
    if (ctrl.GetType() != typeof(FileUpload))
    {
        continue;
    }

    //Do the saving of the file here
}

, , : . - ?

+3

Source: https://habr.com/ru/post/1769754/


All Articles