Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi



i had created the dynamic button and added an event handler to it , and it was working in the best way.


my sample code is:
Button btn = new Button();
     btn.ID = "btn";
     btn.Text = "Button";
     btn.Click += new System.EventHandler(btn_Click);

     this.form1.Controls.Add(btn);


here iam getting the good result when button is clicked


my problem is
i had create the table and added the buttons dynamically with C#.net programming, and everything is fine here,i had generated the eventhandler also, but it is not working

sample code:
TableCell cell = new TableCell();
                if (j == 0)
                {
                    Button b = new Button();
                    b.Text = dt.Rows[i][j].ToString();
                    b.ID = i + "," + j+"Button";
                    b.Click += new EventHandler(b_Click);
                    cell.Controls.Add(b);
                    row.Cells.Add(cell);
                }



so please help me


thanks in advanced
Posted

1 solution

I am guessing that you are not recreating the dynamic table, button etc on postback.

Dynamically added controls need to be recreated in order for postback methods and viewstate to function correctly.
 
Share this answer
 
Comments
[no name] 22-Nov-11 4:26am    
thankq your right

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900