I
Imran Masud
Hi,
I am trying to add a checkbox dynamically in reply to a button click.
Each button click will add a new checkbox object to an ArrayList
Object. I store this ArrayList object in the session and populate it.
private void Button1_Click(object sender, System.EventArgs e){
CheckBox cb = new CheckBox();
cb.ID = cb.GetType().ToString()+((char)(checkList.Count+64)).ToString();
cb.Text = ((char)(checkList.Count+64)).ToString();
cb.AutoPostBack =true;
this.checkList.Add(cb); // ArrayList object
}
I have overloaded OnPreRender method and add the checkbox to my user
control as shown in the code below.
protected override void OnPreRender(EventArgs e)
{
foreach (CheckBox cb in checkList)
{
this.Controls.Add(cb);
}
base.OnPreRender (e);
}
My problem is the state of the checkboxes are not maintained. If I
have added
2 checkboxes and then I click on them, and afterwards I click the
button again
a new checkbox will be added but 1st two be become unchecked.
I will be really grateful, if any of webcontrol guru's outthere
can help me with this problem.
Regards
Imran
I am trying to add a checkbox dynamically in reply to a button click.
Each button click will add a new checkbox object to an ArrayList
Object. I store this ArrayList object in the session and populate it.
private void Button1_Click(object sender, System.EventArgs e){
CheckBox cb = new CheckBox();
cb.ID = cb.GetType().ToString()+((char)(checkList.Count+64)).ToString();
cb.Text = ((char)(checkList.Count+64)).ToString();
cb.AutoPostBack =true;
this.checkList.Add(cb); // ArrayList object
}
I have overloaded OnPreRender method and add the checkbox to my user
control as shown in the code below.
protected override void OnPreRender(EventArgs e)
{
foreach (CheckBox cb in checkList)
{
this.Controls.Add(cb);
}
base.OnPreRender (e);
}
My problem is the state of the checkboxes are not maintained. If I
have added
2 checkboxes and then I click on them, and afterwards I click the
button again
a new checkbox will be added but 1st two be become unchecked.
I will be really grateful, if any of webcontrol guru's outthere
can help me with this problem.
Regards
Imran