%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Untitled Page
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
public int nrOfControls
{
get
{
if (Session["nrControls"] == null)
Session["nrControls"] = 0;
return (int)Session["nrControls"];
}
set { Session["nrControls"] = value; }
}
protected void Page_Init(object sender, EventArgs ea)
{
ListItem li;
if (!IsPostBack)
{
nrOfControls = 0;
}
for (int i = 0; i <= 5; i++)
{
li = new ListItem(i.ToString());
ddl1.Items.Add(li);
}
LoadControls();
}
protected void ddl1_Click(object sender, EventArgs ea)
{
nrOfControls = int.Parse(ddl1.SelectedValue);
//Remove previously created fileupload controls
for (int i = 0; i < Placeholder1.Controls.Count; i++)
{
if (Placeholder1.Controls[i] is FileUpload)
Placeholder1.Controls.RemoveAt(i--);
}
LoadControls();
}
private void LoadControls()
{
FileUpload fu;
for (int i = 0; i < nrOfControls; i++)
{
fu = new FileUpload();
fu.Style.Add("display", "block");
fu.ID = "fu" + i;
Placeholder1.Controls.Add(fu);
}
}
void b_Click(object sender, EventArgs e)
{
Label lbl = new Label();
lbl.ID = "lbl1";
lbl.Text = "lbl ";
foreach (Control c in Placeholder1.Controls)
{
if (c is FileUpload)
{
//Response.Write(((FileUpload)c).FileName + "
");
lbl.Text += ((FileUpload)c).FileName;
}
}
Placeholder2.Controls.Add(lbl);
}
protected void Page_Load(object sender, EventArgs e)
{
if (int.Parse(ddl1.SelectedValue) > 0)
{
Button b;
b = new Button();
b.ID = "b1";
b.Text = "Submit";
b.Click += new EventHandler(b_Click);
Placeholder2.Controls.Add(b);
Updatepanel1.Triggers.Add(Upsite.CodeBlocks.getTrigger(b,"Click"));
}
}
}