Add click event for a dynamic button in asp.net
<p>This is my .aspx.cs code:</p>

<pre><code>public partial class Bus : System.Web.UI.Page
{    
    protected void btnSearchBus_Click(object sender, EventArgs e)
    {      
        foreach (Panel p in buses.Controls.OfType&lt;Panel&gt;())
        {   
            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
    }

}
</code></pre>

<p>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.</p>

<p>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.</p>