title: Dynamically generate buttons c # asp.net
body: <p>Friends I have a question, I have a button to generate buttons, which generates 5 buttons dynamically and they have a click event that redirects me to a page, but when I click on the generated buttons it reloads the page and does nothing.</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  
  namespace pruebastack
  {
      public partial class WebForm1 : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
  
          }
  
          protected void btngenerar_Click(object sender, EventArgs e)
          {
              for(int i=1; i&lt;=5; i++)
              {
                  System.Web.UI.WebControls.Button Button1 = new System.Web.UI.WebControls.Button();
                  Button1.Text = &quot;boton&quot; + i;
                  Button1.Click += delegate
                  {
                      Response.Redirect(&quot;https://www.udemy.com/courses/search/?p=&quot;+i+&quot;&amp;q=java&quot;);
                      
                  };
                  this.Panel1.Controls.Add(Button1);
              }
              
          }
      }
  }
  </code></pre>