1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| public class DOPForm : WebControl
{
private List<string> Controles
{
get
{
if (ViewState["Controles"] == null)
ViewState["Controles"] = new List<string>();
return (List<string>)ViewState["Controles"];
}
set
{
ViewState["Controles"] = value;
}
}
Table tablePrincipale = new Table();
Button boutonAjout = new Button();
Button btValider = new Button();
public DOPForm()
{
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (Page.IsPostBack)
{
foreach (string i in Controles)
{
Button tb = new Button();
tb.ID = i.ToString();
tb.UseSubmitBehavior = false;
tb.Text = tb.ID;
Controls.Add(new LiteralControl("<br />"));
Controls.Add(tb);
Controls.Add(new LiteralControl("<br />"));
}
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
boutonAjout.Click += new EventHandler(ajout_Click);
btValider.Click += new EventHandler(btValider_Click);
}
void btValider_Click(object sender, EventArgs e)
{
int i = 2;
}
void ajout_Click(object sender, EventArgs e)
{
string newGuid = Guid.NewGuid().ToString();
Button tb = new Button();
tb.ID = newGuid;
tb.Text = tb.ID;
Controls.Add(new LiteralControl("<br />"));
Controls.Add(tb);
Controls.Add(new LiteralControl("<br />"));
Controles.Add(newGuid);
}
protected override void CreateChildControls()
{
base.CreateChildControls();
Controls.Add(boutonAjout);
boutonAjout.ID = "btAjout";
boutonAjout.Text = "+ Ajouter";
btValider.Text = "Valider";
Controls.Add(new LiteralControl("<br />"));
Controls.Add(btValider);
Controls.Add(new LiteralControl("<hr />"));
}
} |
Partager