473,324 Members | 2,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Dynamic Checkboxes problem!

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


Nov 16 '05 #1
10 4562
Hi Steven,

I think you should set AutoPostBack="True".

Jie

"Steven" wrote:
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


Nov 16 '05 #2
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" <Pe*****@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
Hi Steven,

I think you should set AutoPostBack="True".

Jie

"Steven" wrote:
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


Nov 16 '05 #3
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" wrote:
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" <Pe*****@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
Hi Steven,

I think you should set AutoPostBack="True".

Jie

"Steven" wrote:
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



Nov 16 '05 #4
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" <Pe*****@discussions.microsoft.com> wrote in message
news:31**********************************@microsof t.com...
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" wrote:
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" <Pe*****@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
> Hi Steven,
>
> I think you should set AutoPostBack="True".
>
> Jie
>
> "Steven" wrote:
>
>> 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
>>
>>
>>
>>
>>


Nov 16 '05 #5
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" wrote:
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" <Pe*****@discussions.microsoft.com> wrote in message
news:31**********************************@microsof t.com...
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" wrote:
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" <Pe*****@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
> Hi Steven,
>
> I think you should set AutoPostBack="True".
>
> Jie
>
> "Steven" wrote:
>
>> 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
>>
>>
>>
>>
>>


Nov 16 '05 #6
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" wrote:
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" <Pe*****@discussions.microsoft.com> wrote in message
news:31**********************************@microsof t.com...
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" wrote:
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" <Pe*****@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
> Hi Steven,
>
> I think you should set AutoPostBack="True".
>
> Jie
>
> "Steven" wrote:
>
>> 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
>>
>>
>>
>>
>>


Nov 16 '05 #7
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?
Nov 16 '05 #8
Copied your code into a empty web form, like below,

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

"Steven" wrote:
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" <Pe*****@discussions.microsoft.com> wrote in message
news:31**********************************@microsof t.com...
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" wrote:
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" <Pe*****@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
> Hi Steven,
>
> I think you should set AutoPostBack="True".
>
> Jie
>
> "Steven" wrote:
>
>> 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
>>
>>
>>
>>
>>


Nov 16 '05 #9
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" <Pe*****@discussions.microsoft.com> wrote in message
news:5F**********************************@microsof t.com...
Copied your code into a empty web form, like below,

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

"Steven" wrote:
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" <Pe*****@discussions.microsoft.com> wrote in message
news:31**********************************@microsof t.com...
> 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" wrote:
>
>> 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" <Pe*****@discussions.microsoft.com> wrote in message
>> news:2A**********************************@microsof t.com...
>> > Hi Steven,
>> >
>> > I think you should set AutoPostBack="True".
>> >
>> > Jie
>> >
>> > "Steven" wrote:
>> >
>> >> 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
>> >>
>> >>
>> >>
>> >>
>> >>
>>
>>
>>


Nov 16 '05 #10
you can try CheckBoxList control. probably meet you requirement.

"Steven" wrote:
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" <Pe*****@discussions.microsoft.com> wrote in message
news:5F**********************************@microsof t.com...
Copied your code into a empty web form, like below,

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

"Steven" wrote:
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" <Pe*****@discussions.microsoft.com> wrote in message
news:31**********************************@microsof t.com...
> 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" wrote:
>
>> 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" <Pe*****@discussions.microsoft.com> wrote in message
>> news:2A**********************************@microsof t.com...
>> > Hi Steven,
>> >
>> > I think you should set AutoPostBack="True".
>> >
>> > Jie
>> >
>> > "Steven" wrote:
>> >
>> >> 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
>> >>
>> >>
>> >>
>> >>
>> >>
>>
>>
>>


Nov 16 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: middletree | last post by:
Hate to post this in a separate post, but felt that the last thread was too far down to get noticed. It is called dynamic checkboxes, and it contained some good advice for me, but it led to...
8
by: DylanM | last post by:
I have some checkboxes that are generated from the results of a database search. At the moment, the checkboxes are part of a table making up a form. Users are going through the form, clicking the...
2
by: trank | last post by:
I created some checkboxes(<input type=checkbox>) dynamically,and then I'd like to access these checkboxes in code behind using C#. For they are not standard controls like Windows Checkbox, I can't...
3
by: Jack Black | last post by:
Using VS.Net 2k3 to build ASP.Net app with VB code-behind pages... Hi, all! I've been struggling with getting a dynamically-generated CheckBoxList generated. I've finally been able to get the...
34
by: clinttoris | last post by:
Hello Experts, I have been told to post this in the Javascript forum as I want to do this client side just before my form gets submitted. Once the user clicks the submit button a javascript...
1
by: Kevin R | last post by:
This is one of the weirdest problems I have ever run into. I have had to trim down a bunch of code to give a sample that is more easily readable by those who will view this. Here is the problem:...
1
by: tamari | last post by:
I have a strange problem changing the checked value of dynamically created checkboxes within code. This is what is happening. Depending what is selected I create checkboxes within a panel. These...
2
by: scottSD | last post by:
Hi everyone. this is my first post here, but i've found quite a bit of great information from reading the forums in the past. i'm not sure if what i'm trying to do is possible or not, but here it...
0
by: galien8 | last post by:
Dear Newsgroup Readers, I have a problem with dynamic controls, in a DotNetNuke module, and event handlers in VB.NET ASP.NET 2.0. Events are firing and being handled, sometimes good but also...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.