title: No server-side click event for dynamically-generated LinkButton
body: <p>I'm trying to add a new section on one of my system's main pages (web forms) that would allow users to see documents they've uploaded into folders they've created.  I don't know in advance how many folders they've set up or what the folders are named.  I'm trying to achieve this by a GridView with a series of dynamically-generated LinkButtons above it, with a LinkButton for each folder.  When the user clicks a LinkButton I will rebind the grid so that it shows documents in that folder.  I was hoping to use a tab control to represent the folders but apparently that isn't available in .NET 3.5.  I am coding in VB.NET.</p>
  
  <p>The issue I'm running into is adding an OnClick event handler dynamically.  The code I am using is basically implementing an OnClientClick event.  If I  add a Javascript function called lnkFolder_Click with an alert it is triggering that function, when I need it to trigger a server-side function to rebind the grid.  I've seen many pages on this problem with various suggestions, including placing the code in the page's PreInit event.  None of these suggestions worked for me, so I'm hoping the StackExchange community can help nudge me in the right direction as it has in the past!  The following code is what I'm trying and is located in the page load event.</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code>        Dim dtFolders As DataTable
          Dim i As Integer
  
          dtFolders = DAL.GetClientFolders(Session("ClientKey"))
          If dtFolders.Rows.Count &gt; 0 Then
              For i = 0 to dtFolders.Rows.Count - 1
                  Dim lnkFolder As LinkButton = New LinkButton
                  lnkFolder.ID = "lnkFolder" &amp; i.ToString
                  lnkFolder.Text = dtFolders.Rows(i)("FolderName")
                  lnkFolder.CommandArgument = i
                  lnkFolder.Attributes.Add("OnClick", "lnkFolder_Click()")
                  'lnkFolder.OnClientClick += New EventHandler(lnkFolder_Click)
                  phFolders.Controls.Add(lnkFolder)                  
              Next
          End If
  </code></pre>
  
  <p>The lnkFolder_Click function is just "stubbed-out" as follows:</p>
  
  <pre><code>Protected Sub lnkFolder_Click(sender As Object, e As EventArgs) Handles lnkFolder.Click
  
          Dim i As Integer
  
          i = 1
  
      End Sub
  </code></pre>