title: Event handler not firing in WebForms
body: <p>i have a page which dynanically create a link when it load, after i click on the link it should loop in the database fetch all the record and display another set of link , then when i click on these link it should give me all information about this particular record it like this one</p>
  
  <p><strong>Q:</strong> when the page loads, it creates the first link which is associated with an event handler, it fire the first event handler (Getname) but it not firing the second event handler (GetnameDetails)</p>
  
  <pre><code>Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
  
          If ViewState.Item("nameload") IsNot Nothing Then
              If ViewState.Item("nameload").ToString = "True" Then
                  Getname(Me, New EventArgs)
              ElseIf ViewState.Item("Getnameload").ToString = "True" Then
                  GetnameDetails(Me, New EventArgs)
              Else
                  CreateNamesButton()
              End If
          Else
              CreateNamesButton()
          End If
  </code></pre>
  
  <hr>
  
  <p>page load and name link create</p>
  
  <pre><code>Private Sub CreateNamesButton()
          Dim btnName As New LinkButton
          btnName .Text = "Name"
          Panel1.Controls.Add(btnName)
          AddHandler btnName .Click, AddressOf Getname
          ViewState.Item("nameload") = False.ToString
      End Sub
  </code></pre>
  
  <hr>
  
  <p>it fire nameload event handler</p>
  
  <pre><code>Private Sub Getname(ByVal sender As Object, ByVal e As EventArgs)
          ' get products list here
          ' and set handlers for each link
  
          Dim testDb As New customer
          Dim arr As ArrayList = testDb.DbLoop()
          Dim ObjCustList As CustomerBo
          Dim CustInt As Integer
          Dim str As String
  
          Dim link As LinkButton
  
          For Each ObjCustList In arr
              CustInt = ObjCustList.Cus_Id
              link = New LinkButton
              Panel1.Controls.Add(New LiteralControl("&lt;br /&gt;"))
              link.ID = CustInt
              link.Text = ObjCustList.FirstName
              link.CommandArgument = CustInt
              str = link.CommandArgument
              AddHandler link.Click, AddressOf GetnameDetails
              Me.Panel1.Controls.Add(link)
  
          Next ObjCustList
  
          ViewState.Item("nameload") = True.ToString
  
      End Sub
  </code></pre>
  
  <hr>
  
  <p>it not fire </p>
  
  <pre><code>Private Sub GetnameDetails(ByVal sender As Object, ByVal e As EventArgs)
  
          Dim getRecord As New CustomerBo
          Dim lbLink As LinkButton = CType(sender, LinkButton)
          Dim CustomerID As String = lbLink.CommandArgument
          Dim getLink As String = lbLink.Text
          Dim SendCustID As Integer
          SendCustID = CInt(CustomerID)
          getRecord.Cus_Id = SendCustID
  
          Dim getAllcatInfo As New customer
          getRecord = getAllcatInfo.R_List(getRecord)
          Panel1.Controls.Add(New LiteralControl("&lt;table&gt;&lt;tr&gt;"))
          Panel1.Controls.Add(New LiteralControl("&lt;td colspan=2 align=center    valign=middle &gt;"))
          Panel1.Controls.Add(New LiteralControl(getRecord.FirstName))
          Panel1.Controls.Add(New LiteralControl("&lt;/td&gt;"))
          Panel1.Controls.Add(New LiteralControl("&lt;td&gt;"))
          Panel1.Controls.Add(New LiteralControl(getRecord.LastName))
          Panel1.Controls.Add(New LiteralControl("&lt;/td&gt;"))
          Panel1.Controls.Add(New LiteralControl("&lt;td&gt;"))
          Panel1.Controls.Add(New LiteralControl(getRecord.Telephone))
          Panel1.Controls.Add(New LiteralControl("&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;"))
          ViewState.Item("Getnameload") = True.ToString
  
          'get product details here
      End Sub
  </code></pre>
  
  <p>what am doing wrong thank</p>