By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,780 Members | 1,520 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,780 IT Pros & Developers. It's quick & easy.

dynamically created checkbox event not working

100+
P: 115
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
Share this Question
Share on Google+
3 Replies


kenobewan
Expert 2.5K+
P: 4,871
Did you create it as a server object? One of the risks of creating objects dynamically...
Aug 4 '08 #2

100+
P: 115
Hi

do u have any sample
pls give me
Aug 5 '08 #3

Frinavale
Expert Mod 5K+
P: 9,731
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

Post your reply

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