|
-
September 28th, 2010, 07:25 AM
#1
How to handle dynamic buttons?
I created buttons dynamically with a loop. Into a table and it was successfully added.
Here's a part of my code.
PHP Code:
for (int i = 0; i < 6; i++) { Button btn = new Button(); btn.Text = "Available"; btn.ID = "btn" + i; btn.Click += new System.EventHandler(btn_Click); tc.Controls.Add(btn); }
public void btn_Click(object sender, System.EventArgs e) { Button currentButton = (Button)sender; string ID = currentButton.ID; switch(ID) { case "btn1": subjectID = subjectIDs[0]; break; case "btn2": subjectID = subjectIDs[1]; break; case "btn3": subjectID = subjectIDs[2]; break; case "btn4": subjectID = subjectIDs[3]; break; case "btn5": subjectID = subjectIDs[4]; break; case "btn6": subjectID = subjectIDs[5]; break; } }
But when I click the buttons that were created, the event isn't firing.
Is my button handler correct?
Last edited by Mercvapor; September 28th, 2010 at 08:07 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|