This is my .aspx.cs code:
public partial class Bus : System.Web.UI.Page
{
protected void btnSearchBus_Click(object sender, EventArgs e)
{
foreach (Panel p in buses.Controls.OfType<Panel>())
{
Button busSelectBtn = new Button();
busSelectBtn.Click += btn_Click;
}
}
void btn_Click(object sender, EventArgs e)
{
//This part doesn't execute when the button is clicked
}
}
The foreach loop executes when a button "btnSearchBus" is clicked. The foreach loop loops through every Panel inside another Panel "buses" and creates a button for each Panel.
What I want to do is add a click (or onclick) event to each of those buttons created. I checked a number of posts on how to achieve this but wasn't lucky. I am not sure what to do.