ksaul
asked on
If I dynamically add controls in ASP.NET, how do I retrieve their values on subsequent posting?
If I dynamically add controls in ASP.NET, how do I retrieve their values on subsequent posting?
For example this form:
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="Dr opDownList 1_Selected IndexChang ed">
<asp:ListItem>1</asp:ListI tem>
<asp:ListItem>2</asp:ListI tem>
<asp:ListItem>3</asp:ListI tem>
</asp:DropDownList><br />
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="436px">
<asp:FileUpload ID="fileUpload1" runat="server" Width="429px" /></asp:Panel>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<br />
<br />
<asp:ListBox ID="ListBox1" runat="server" Width="379px"></asp:ListBo x></div>
</form>
has a dropdown list that when changed runs this:
for (int i = 2; i < Convert.ToInt32(DropDownLi st1.Select edIndex)+ 2; i++)
{
FileUpload fileUpload = new FileUpload();
fileUpload.ID = "fileUpload" + i.ToString();
Panel1.Controls.Add(fileUp load);
}
I need code for the button that will get the file names from however many controls were added with the drop down list.
For example this form:
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="Dr
<asp:ListItem>1</asp:ListI
<asp:ListItem>2</asp:ListI
<asp:ListItem>3</asp:ListI
</asp:DropDownList><br />
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="436px">
<asp:FileUpload ID="fileUpload1" runat="server" Width="429px" /></asp:Panel>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<br />
<br />
<asp:ListBox ID="ListBox1" runat="server" Width="379px"></asp:ListBo
</form>
has a dropdown list that when changed runs this:
for (int i = 2; i < Convert.ToInt32(DropDownLi
{
FileUpload fileUpload = new FileUpload();
fileUpload.ID = "fileUpload" + i.ToString();
Panel1.Controls.Add(fileUp
}
I need code for the button that will get the file names from however many controls were added with the drop down list.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm going to split points for your suggestions.
I decided that for this situation it was better to create 25 design-time FileUpload controls setting their style property to display:none and then use javascript to show and enable as many as the user needed. That made looping through the controls after the post much easier.
I decided that for this situation it was better to create 25 design-time FileUpload controls setting their style property to display:none and then use javascript to show and enable as many as the user needed. That made looping through the controls after the post much easier.
ASKER
Can you give me some sample code of how to do that? I would need to retain entered values when I re-create them.