Event on Dynamic Control - ASP

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
 
G

Guest

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
 
G

Guest

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.
 
O

olduncleamos

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top