Dynamic Checkboxes problem!

S

Steven

I create the checkboxes dynamically on my webform (aspx). after I create
them, when I check any of the checkboxes, nothing happens. Here is my code
...

ArrayList LayerNameList1 = LayerNameList;

CheckBox[] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox[250];
foreach(string item in LayerNameList1)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add("font-family", "Arial");
FieldCell.Style.Add("font-size", "smaller");
checkBoxArray[BoxCount] = new CheckBox();
checkBoxArray[BoxCount].ID = Convert.ToString(BoxCount);
checkBoxArray[BoxCount].Text = item;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray[BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow);
BoxCount++;
}
this.placeHolder.Controls.Add(ContainerTable);
}

public void checkBox_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox cb = (CheckBox) sender;

if (cb.Checked)
{ testdel.Text = "1"; }
else
{ testdel.Text = "2";
}
}

Any suggestions?

Regards
Praveen
 
S

Steven

Hello Peng,

Could you please tell me, where should I set AutoPostBack="True" in the
below code. I tried in checkBox_CheckedChanged function. But seems I'm
missing something.

Regards
Steven

Peng Jie said:
Hi Steven,

I think you should set AutoPostBack="True".

Jie

Steven said:
I create the checkboxes dynamically on my webform (aspx). after I create
them, when I check any of the checkboxes, nothing happens. Here is my
code
...

ArrayList LayerNameList1 = LayerNameList;

CheckBox[] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox[250];
foreach(string item in LayerNameList1)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add("font-family", "Arial");
FieldCell.Style.Add("font-size", "smaller");
checkBoxArray[BoxCount] = new CheckBox();
checkBoxArray[BoxCount].ID = Convert.ToString(BoxCount);
checkBoxArray[BoxCount].Text = item;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray[BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow);
BoxCount++;
}
this.placeHolder.Controls.Add(ContainerTable);
}

public void checkBox_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox cb = (CheckBox) sender;

if (cb.Checked)
{ testdel.Text = "1"; }
else
{ testdel.Text = "2";
}
}

Any suggestions?

Regards
Praveen
 
G

Guest

What I mean is you can add

checkBoxArray[BoxCount].AutoPostBack = true;

into your foreach statement.
Then you can fire server side event and call CheckedChanged function.

Steven said:
Hello Peng,

Could you please tell me, where should I set AutoPostBack="True" in the
below code. I tried in checkBox_CheckedChanged function. But seems I'm
missing something.

Regards
Steven

Peng Jie said:
Hi Steven,

I think you should set AutoPostBack="True".

Jie

Steven said:
I create the checkboxes dynamically on my webform (aspx). after I create
them, when I check any of the checkboxes, nothing happens. Here is my
code
...

ArrayList LayerNameList1 = LayerNameList;

CheckBox[] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox[250];
foreach(string item in LayerNameList1)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add("font-family", "Arial");
FieldCell.Style.Add("font-size", "smaller");
checkBoxArray[BoxCount] = new CheckBox();
checkBoxArray[BoxCount].ID = Convert.ToString(BoxCount);
checkBoxArray[BoxCount].Text = item;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray[BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow);
BoxCount++;
}
this.placeHolder.Controls.Add(ContainerTable);
}

public void checkBox_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox cb = (CheckBox) sender;

if (cb.Checked)
{ testdel.Text = "1"; }
else
{ testdel.Text = "2";
}
}

Any suggestions?

Regards
Praveen
 
S

Steven

Hello Peng,

I tried this ..
checkBoxArray[BoxCount].AutoPostBack = true;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged11);



but some how when I check the checkbox, the checkBox_CheckedChanged event is
not firing. Its not even hitting the function.



Any suggestions

-- Steven



Peng Jie said:
What I mean is you can add

checkBoxArray[BoxCount].AutoPostBack = true;

into your foreach statement.
Then you can fire server side event and call CheckedChanged function.

Steven said:
Hello Peng,

Could you please tell me, where should I set AutoPostBack="True" in the
below code. I tried in checkBox_CheckedChanged function. But seems I'm
missing something.

Regards
Steven

Peng Jie said:
Hi Steven,

I think you should set AutoPostBack="True".

Jie

:

I create the checkboxes dynamically on my webform (aspx). after I
create
them, when I check any of the checkboxes, nothing happens. Here is my
code
...

ArrayList LayerNameList1 = LayerNameList;

CheckBox[] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox[250];
foreach(string item in LayerNameList1)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add("font-family", "Arial");
FieldCell.Style.Add("font-size", "smaller");
checkBoxArray[BoxCount] = new CheckBox();
checkBoxArray[BoxCount].ID = Convert.ToString(BoxCount);
checkBoxArray[BoxCount].Text = item;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray[BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow);
BoxCount++;
}
this.placeHolder.Controls.Add(ContainerTable);
}

public void checkBox_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox cb = (CheckBox) sender;

if (cb.Checked)
{ testdel.Text = "1"; }
else
{ testdel.Text = "2";
}
}

Any suggestions?

Regards
Praveen
 
G

Guest

Copied your code into a empty web form, like below,

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
// test for log4net status
ILog Log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Log.Info("Default page.");


ArrayList LayerNameList1 = new ArrayList();
LayerNameList1.Add("test1");
LayerNameList1.Add("test2");
LayerNameList1.Add("test3");

CheckBox[] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox[250];
foreach(string item in LayerNameList1)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add("font-family", "Arial");
FieldCell.Style.Add("font-size", "smaller");
checkBoxArray[BoxCount] = new CheckBox();
checkBoxArray[BoxCount].ID = Convert.ToString(BoxCount);
checkBoxArray[BoxCount].Text = item;
checkBoxArray[BoxCount].AutoPostBack = true;
checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray[BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow);
BoxCount++;
}
this.placeHolder.Controls.Add(ContainerTable);
}

public void checkBox_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox cb = (CheckBox) sender;
if (cb.Checked)
{ testdel.Text = "1"; }
else
{
testdel.Text = "2";
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion


It works for me. Did you create checkboxes in pageload?


Steven said:
Hello Peng,

I tried this ..
checkBoxArray[BoxCount].AutoPostBack = true;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged11);



but some how when I check the checkbox, the checkBox_CheckedChanged event is
not firing. Its not even hitting the function.



Any suggestions

-- Steven



Peng Jie said:
What I mean is you can add

checkBoxArray[BoxCount].AutoPostBack = true;

into your foreach statement.
Then you can fire server side event and call CheckedChanged function.

Steven said:
Hello Peng,

Could you please tell me, where should I set AutoPostBack="True" in the
below code. I tried in checkBox_CheckedChanged function. But seems I'm
missing something.

Regards
Steven

Hi Steven,

I think you should set AutoPostBack="True".

Jie

:

I create the checkboxes dynamically on my webform (aspx). after I
create
them, when I check any of the checkboxes, nothing happens. Here is my
code
...

ArrayList LayerNameList1 = LayerNameList;

CheckBox[] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox[250];
foreach(string item in LayerNameList1)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add("font-family", "Arial");
FieldCell.Style.Add("font-size", "smaller");
checkBoxArray[BoxCount] = new CheckBox();
checkBoxArray[BoxCount].ID = Convert.ToString(BoxCount);
checkBoxArray[BoxCount].Text = item;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray[BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow);
BoxCount++;
}
this.placeHolder.Controls.Add(ContainerTable);
}

public void checkBox_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox cb = (CheckBox) sender;

if (cb.Checked)
{ testdel.Text = "1"; }
else
{ testdel.Text = "2";
}
}

Any suggestions?

Regards
Praveen
 
G

Guest

Copied your code into a empty web form, like below,

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
// test for log4net status
ILog Log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Log.Info("Default page.");


ArrayList LayerNameList1 = new ArrayList();
LayerNameList1.Add("test1");
LayerNameList1.Add("test2");
LayerNameList1.Add("test3");

CheckBox[] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox[250];
foreach(string item in LayerNameList1)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add("font-family", "Arial");
FieldCell.Style.Add("font-size", "smaller");
checkBoxArray[BoxCount] = new CheckBox();
checkBoxArray[BoxCount].ID = Convert.ToString(BoxCount);
checkBoxArray[BoxCount].Text = item;
checkBoxArray[BoxCount].AutoPostBack = true;
checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray[BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow);
BoxCount++;
}
this.placeHolder.Controls.Add(ContainerTable);
}

public void checkBox_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox cb = (CheckBox) sender;
if (cb.Checked)
{ testdel.Text = "1"; }
else
{
testdel.Text = "2";
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion


It works for me. Did you create checkboxes in pageload?



Steven said:
Hello Peng,

I tried this ..
checkBoxArray[BoxCount].AutoPostBack = true;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged11);



but some how when I check the checkbox, the checkBox_CheckedChanged event is
not firing. Its not even hitting the function.



Any suggestions

-- Steven



Peng Jie said:
What I mean is you can add

checkBoxArray[BoxCount].AutoPostBack = true;

into your foreach statement.
Then you can fire server side event and call CheckedChanged function.

Steven said:
Hello Peng,

Could you please tell me, where should I set AutoPostBack="True" in the
below code. I tried in checkBox_CheckedChanged function. But seems I'm
missing something.

Regards
Steven

Hi Steven,

I think you should set AutoPostBack="True".

Jie

:

I create the checkboxes dynamically on my webform (aspx). after I
create
them, when I check any of the checkboxes, nothing happens. Here is my
code
...

ArrayList LayerNameList1 = LayerNameList;

CheckBox[] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox[250];
foreach(string item in LayerNameList1)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add("font-family", "Arial");
FieldCell.Style.Add("font-size", "smaller");
checkBoxArray[BoxCount] = new CheckBox();
checkBoxArray[BoxCount].ID = Convert.ToString(BoxCount);
checkBoxArray[BoxCount].Text = item;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray[BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow);
BoxCount++;
}
this.placeHolder.Controls.Add(ContainerTable);
}

public void checkBox_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox cb = (CheckBox) sender;

if (cb.Checked)
{ testdel.Text = "1"; }
else
{ testdel.Text = "2";
}
}

Any suggestions?

Regards
Praveen
 
G

Guest

Copied your code into a empty web form, like below,

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
// test for log4net status
ILog Log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Log.Info("Default page.");


ArrayList LayerNameList1 = new ArrayList();
LayerNameList1.Add("test1");
LayerNameList1.Add("test2");
LayerNameList1.Add("test3");

CheckBox[] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox[250];
foreach(string item in LayerNameList1)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add("font-family", "Arial");
FieldCell.Style.Add("font-size", "smaller");
checkBoxArray[BoxCount] = new CheckBox();
checkBoxArray[BoxCount].ID = Convert.ToString(BoxCount);
checkBoxArray[BoxCount].Text = item;
checkBoxArray[BoxCount].AutoPostBack = true;
checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray[BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow);
BoxCount++;
}
this.placeHolder.Controls.Add(ContainerTable);
}

public void checkBox_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox cb = (CheckBox) sender;
if (cb.Checked)
{ testdel.Text = "1"; }
else
{
testdel.Text = "2";
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion


It works for me. Did you create checkboxes in pageload?
 
G

Guest

Copied your code into a empty web form, like below,

It exactly works for me. Did you create checkboxes in pageload?



Steven said:
Hello Peng,

I tried this ..
checkBoxArray[BoxCount].AutoPostBack = true;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged11);



but some how when I check the checkbox, the checkBox_CheckedChanged event is
not firing. Its not even hitting the function.



Any suggestions

-- Steven



Peng Jie said:
What I mean is you can add

checkBoxArray[BoxCount].AutoPostBack = true;

into your foreach statement.
Then you can fire server side event and call CheckedChanged function.

Steven said:
Hello Peng,

Could you please tell me, where should I set AutoPostBack="True" in the
below code. I tried in checkBox_CheckedChanged function. But seems I'm
missing something.

Regards
Steven

Hi Steven,

I think you should set AutoPostBack="True".

Jie

:

I create the checkboxes dynamically on my webform (aspx). after I
create
them, when I check any of the checkboxes, nothing happens. Here is my
code
...

ArrayList LayerNameList1 = LayerNameList;

CheckBox[] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox[250];
foreach(string item in LayerNameList1)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add("font-family", "Arial");
FieldCell.Style.Add("font-size", "smaller");
checkBoxArray[BoxCount] = new CheckBox();
checkBoxArray[BoxCount].ID = Convert.ToString(BoxCount);
checkBoxArray[BoxCount].Text = item;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray[BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow);
BoxCount++;
}
this.placeHolder.Controls.Add(ContainerTable);
}

public void checkBox_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox cb = (CheckBox) sender;

if (cb.Checked)
{ testdel.Text = "1"; }
else
{ testdel.Text = "2";
}
}

Any suggestions?

Regards
Praveen
 
S

Steven

Thank you for the code and explanation.

If I recreate the controls on page load everything works fine. But I do not
want to recreate the controls on page load. I just want to create the check
boxes only when I click the button.

Regards
Steven


Peng Jie said:
Copied your code into a empty web form, like below,

It exactly works for me. Did you create checkboxes in pageload?



Steven said:
Hello Peng,

I tried this ..
checkBoxArray[BoxCount].AutoPostBack = true;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged11);



but some how when I check the checkbox, the checkBox_CheckedChanged event
is
not firing. Its not even hitting the function.



Any suggestions

-- Steven



Peng Jie said:
What I mean is you can add

checkBoxArray[BoxCount].AutoPostBack = true;

into your foreach statement.
Then you can fire server side event and call CheckedChanged function.

:

Hello Peng,

Could you please tell me, where should I set AutoPostBack="True" in
the
below code. I tried in checkBox_CheckedChanged function. But seems I'm
missing something.

Regards
Steven

Hi Steven,

I think you should set AutoPostBack="True".

Jie

:

I create the checkboxes dynamically on my webform (aspx). after I
create
them, when I check any of the checkboxes, nothing happens. Here is
my
code
...

ArrayList LayerNameList1 = LayerNameList;

CheckBox[] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new
HtmlTable();
checkBoxArray = new CheckBox[250];
foreach(string item in LayerNameList1)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add("font-family", "Arial");
FieldCell.Style.Add("font-size", "smaller");
checkBoxArray[BoxCount] = new CheckBox();
checkBoxArray[BoxCount].ID = Convert.ToString(BoxCount);
checkBoxArray[BoxCount].Text = item;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray[BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow);
BoxCount++;
}
this.placeHolder.Controls.Add(ContainerTable);
}

public void checkBox_CheckedChanged(object sender, System.EventArgs
e)
{
CheckBox cb = (CheckBox) sender;

if (cb.Checked)
{ testdel.Text = "1"; }
else
{ testdel.Text = "2";
}
}

Any suggestions?

Regards
Praveen
 
G

Guest

you can try CheckBoxList control. probably meet you requirement.

Steven said:
Thank you for the code and explanation.

If I recreate the controls on page load everything works fine. But I do not
want to recreate the controls on page load. I just want to create the check
boxes only when I click the button.

Regards
Steven


Peng Jie said:
Copied your code into a empty web form, like below,

It exactly works for me. Did you create checkboxes in pageload?



Steven said:
Hello Peng,

I tried this ..
checkBoxArray[BoxCount].AutoPostBack = true;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged11);



but some how when I check the checkbox, the checkBox_CheckedChanged event
is
not firing. Its not even hitting the function.



Any suggestions

-- Steven



What I mean is you can add

checkBoxArray[BoxCount].AutoPostBack = true;

into your foreach statement.
Then you can fire server side event and call CheckedChanged function.

:

Hello Peng,

Could you please tell me, where should I set AutoPostBack="True" in
the
below code. I tried in checkBox_CheckedChanged function. But seems I'm
missing something.

Regards
Steven

Hi Steven,

I think you should set AutoPostBack="True".

Jie

:

I create the checkboxes dynamically on my webform (aspx). after I
create
them, when I check any of the checkboxes, nothing happens. Here is
my
code
...

ArrayList LayerNameList1 = LayerNameList;

CheckBox[] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new
HtmlTable();
checkBoxArray = new CheckBox[250];
foreach(string item in LayerNameList1)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add("font-family", "Arial");
FieldCell.Style.Add("font-size", "smaller");
checkBoxArray[BoxCount] = new CheckBox();
checkBoxArray[BoxCount].ID = Convert.ToString(BoxCount);
checkBoxArray[BoxCount].Text = item;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray[BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow);
BoxCount++;
}
this.placeHolder.Controls.Add(ContainerTable);
}

public void checkBox_CheckedChanged(object sender, System.EventArgs
e)
{
CheckBox cb = (CheckBox) sender;

if (cb.Checked)
{ testdel.Text = "1"; }
else
{ testdel.Text = "2";
}
}

Any suggestions?

Regards
Praveen
 

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