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
| public class Test_pour_MC : System.Web.UI.WebControls.WebParts.WebPart
{
private System.Web.UI.WebControls.Label lab_titre;
private System.Web.UI.WebControls.Button btn_cacher_label; //création d'un bouton
private System.Web.UI.WebControls.Button btn_afficher_label; //création d'un bouton
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
lab_titre = new Label();
lab_titre.Text="Label <BR>" ;
//proprité du bouton 'cacher'
btn_cacher_label = new Button(); //Initialisation du bouton
btn_cacher_label.Text = "Cacher label";
btn_cacher_label.Click += new EventHandler(Proc_btn_cacher_label);
//proprité du bouton 'Afficher'
btn_afficher_label = new Button();
btn_afficher_label.Text = "Afficher Label";
btn_afficher_label.Click += new System.EventHandler(Proc_btn_afficher_label);
//this.Controls.Add(btn_afficher_label); si on l'affiche ici, ça fonctionne mais ce n'est pas ce que je recherche.
}
protected override void CreateChildControls()
{
this.Controls.Add(lab_titre);
this.Controls.Add(btn_cacher_label);
}
void Proc_btn_cacher_label(Object sender, EventArgs e) //procédure appelée lors du click sur le bouton 'cacher label'
{
lab_titre.Visible = false;
this.Controls.Add(btn_afficher_label);
btn_cacher_label.Text = "bouton cacher deja appuyé";
}
void Proc_btn_afficher_label(Object sender, EventArgs e) //procédure appelée lors du click sur le bouton 'Afficher label'
{
lab_titre.Visible = true;
lab_titre.Text = "bouton Afficher cliqué";
}
}
} |
Partager