473,401 Members | 2,146 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,401 software developers and data experts.

dynamically created checkbox event not working

115 100+
Hi All

this is my page load event
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         for (int i = 0; i <= 3; i++)
  4.         {
  5.  
  6.             TableRow tr = new TableRow();
  7.             TableCell td1 = new TableCell();
  8.             td1.Text = "1";
  9.             TableCell td2 = new TableCell();
  10.             td2.Text = "2";
  11.             tr.Cells.Add(td1);
  12.             tr.Cells.Add(td2);
  13.             Table1.Rows.Add(tr);
  14.             TableRow tr2 = new TableRow();
  15.             TableCell td3 = new TableCell();
  16.             td3.ColumnSpan = 2;
  17.             CheckBox chk = new CheckBox();
  18.             chk.ID = Convert.ToString(i);
  19.             chk.CheckedChanged += new EventHandler(CheckBox_CheckedChanged);
  20.             td3.Controls.Add(chk);
  21.             tr2.Cells.Add(td3);
  22.             Table1.Rows.Add(tr2);
  23.         }
  24.  
  25.     }
  26.  
  27.  
  28. protected void CheckBox_CheckedChanged(object sender, EventArgs e)
  29.     {
  30.         CheckBox chk = sender as CheckBox;
  31.  
  32.         Label1.Text = chk.Checked ? String.Format("You checked CheckBox '{0}'.", chk.ID) : String.Format("You unchecked CheckBox '{0}'.", chk.ID);
  33.         //Label1.Visible = true;
  34.     }
  35.  
this is my code
but CheckBox_CheckedChanged event not working

pls help
Aug 4 '08 #1
3 1795
kenobewan
4,871 Expert 4TB
Did you create it as a server object? One of the risks of creating objects dynamically...
Aug 4 '08 #2
yogarajan
115 100+
Hi

do u have any sample
pls give me
Aug 5 '08 #3
Frinavale
9,735 Expert Mod 8TB
Hi

do u have any sample
pls give me

I think that you are going to have to declare your checkbox elsewhere....I'm not sure how to use events with C#, but check out this article on how to use dynamic controls in asp.net...

-Frinny
Aug 5 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Steve Caliendo | last post by:
Hi, I am dynamically generating check boxes in the Panel control based on a database field, and I've set the AutoPostBack property to True. How can I determine which CheckBox caused the post...
5
by: bryanp10 | last post by:
I have a page that is almost entirely dynamically created. Textboxes and checkbox are working fine, firing events, and persistent their state. DropDownList is giving me a major headache. All...
1
by: Dan H | last post by:
I have been able to add controls dyanmically to a windows application. And I can get the Click event working beautifully. But now I want to use an another event to change the state of the check box...
2
by: Pete Moss | last post by:
During a postback event, I am having trouble retrieving the state of a CheckBox Control that I am dynamically adding to a DataGrid Control using ASP.NET 1.1. I have no trouble adding the...
2
by: somaskarthic | last post by:
Hi In my php code , i dynamically created table rows on button click event. Each row contain 3 selectboxes, 7 checkboxes . On each click of these elements i need to submit the form and save the...
0
by: Silver Oak | last post by:
I have a DataGrid in which one of the columns is TemplateColumn that was created dynamically using iTemplate. I would like to have multi-row editing capability on the DataGrid. I'm trying to...
12
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the...
2
by: Dica | last post by:
i've got a script that creates a new tablerow + tablecell and appends that to a non dynamically created table control. a new row is added for each recordset returned from my sql statement. within...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.