Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
when other buuton Click event fired, i want create a new button(b1) programiticaly.
b1 is created but when i Click b1 so b1 became hidden and i cant fired b1s event.
what i do so it work correctly
code is blow:

C#
//*********************************************************************************

    protected void checkbutton_Click(object sender, EventArgs e)
    {
        Table tb = new Table();
        for (int k = 0; k < 4; k++)
        {
            TableRow tr = new TableRow();
            TableCell tch = new TableCell();
            tr.Cells.Add(tch);
            for (int j = 0; j < 10; j++)
            {
                TableCell tc = new TableCell();
                Button b1 = new Button();
                b1.Text = ((j + 1) + (k * 10)).ToString();
                b1.Click += new EventHandler(b1_Click);
                tc.Controls.Add(b1);
                tr.Cells.Add(tc);
            }
            tb.Rows.Add(tr);
        }
        place1.Controls.Add(tb);
    }

void b1_Click(object sender, EventArgs e)
{
    Button b2=(Button)sender;
    this.Title = b2.Text;
}
Posted
Updated 4-Sep-12 1:20am
v3

Hi ,
Check this
not firing dynamically cretated button click event[^]
Best Regards
M.Mitwalli
 
Share this answer
 
Comments
r.kh 4-Sep-12 7:49am    
thank for your helping
Mohamed Mitwalli 4-Sep-12 8:02am    
Your welcome :)
Manas Bhardwaj 4-Sep-12 16:16pm    
yup 5!
Mohamed Mitwalli 5-Sep-12 0:50am    
Thanks manas:)
Hi,

Your button get hide because your page is postback when it clicked. You need to write your button creation code in PageLoad/PageInit to work. And don't forget to associate event of that button as well.


Thanks
-Amit Gajjar
 
Share this answer
 

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