First of all you cannot add a <asp:Button
as a string to the page and expect it to work. If you want to add true asp buttons dynamically you have to take a different approach:
Button button = new Button();
button.CssClass = strClass;
button.BackColor = System.Drawing.Color.Green;
button.ID = "Btn1";
button.Text = cellData;
button.Click += new EventHandler(Button1_Click);
PlaceHolder1.Controls.Add(button);
Or you could still add a "normal" HTML button to the page, but then you have to use class=
instead of CssClass=
, which is an attribute of most asp controls (just as BackColor
).
sb.Append("<input type=\"button\" onclick=\"Button1_Click()\" id=\"Btn1\" class=\"" + strClass + "\" value=\"" + cellData + "\"><br />");
Note that the OnClick
is now a javascript call with ()
at the end. Of course it will not fire an event in code behind.