I have some buttons that are being dynamically added to an asp.net page. However the onclick event is not being fired. Here is the code for it being added and it is ran when the page loads. I am very new to ASP.NET so I am sure I am making some basic errors. TIA.
protected void Page_Load(object sender, EventArgs e)
{
FillTable();
string rownum = (goalstable.Rows.Count).ToString();
Button bt = new Button();
bt.Text = "View";
bt.ID = (rownum);
bt.CssClass = "button";
bt.Click += Viewbutton_Click;
goalstable.Rows[1].Cells[0].Controls.Add(bt);
}
FillTable() is a method that fills a table from an SQL DB. The on click event for the button that has been added.
protected void Viewbutton_Click(object sender, EventArgs e)
{
getGID();
setGoalDets();
goals.Style.Add("display", "block");
darkLayer2.Style.Add("display", "block");
}
Any Ideas what I may be doing wrong.