Event on Dynamic Control - ASP

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I've created a dynamic button and checkbox and i want to create an event for
each one of them.
altough i've created the event and assigned them to each control, nothing
happens,
the event is not occurring.
What am i doing wrong?

this is my code for the checkBox:
CheckBox cb = new CheckBox();

cb.Text = "Text";
cb.Font.Bold = true;
cb.ID = "Friend_cb";
cb.Font.Name = "Tahoma";
cb.Font.Size = new FontUnit("16pt");
cb.ForeColor = Color.Blue;
cb.Checked = false;
cb.CheckedChanged += new System.EventHandler(Show_OutSide_TextBox);
cb.EnableViewState = true;
this.form1.Controls.Add(cb);

private void Show_OutSide_TextBox(object sender, System.EventArgs e)
{
if (((CheckBox)sender).Checked == true)
{
Create_Label(0, "<br><br>");
Create_OutSide_Player_TextBox();
}
}

Thanks,
Gidi
 
Hi,
As far as my understanding goes if you are creating dynamic controls then
you need to recreate same controls on postback and also give them same ID as
previously given before postback
 
Hi,
Thanks For the quick reply.

I tried to add the folowing code to my Page_Load()
if (this.IsPostBack)
{
Create_OutSide_Player_CheckBox();
return;
}

and still nothing happens.
 
I tried to add the folowing code to my Page_Load()
if (this.IsPostBack)
{
Create_OutSide_Player_CheckBox();
return;
}

and still nothing happens.

Page_Load is too late. You should do that in Init.
 
Back
Top