title: How do I add an on click event to image button added from code behind
body: <p>I am loading all images in a folder on page load by an image button from code behind.</p>
  
  <p>The images are added correctly but I want to hook up an onclick event unto the image button added dynamically. </p>
  
  <p>Below is my code</p>
  
  <pre><code>  Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
  
          For Each strfilename As String In Directory.GetFiles(Server.MapPath("~/glypics/"))
              Dim imgbtn As New ImageButton
              Dim fileinfo As New FileInfo(strfilename)
  
  
              imgbtn.ImageUrl = "~/glypics/" + fileinfo.Name
              imgbtn.Width = Unit.Pixel(250)
              Panel1.Controls.Add(imgbtn)
              imgbtn.Style.Add("padding", "3px")
    Next
  
      End Sub
  </code></pre>