Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


Dynamically generated Linkbutton does not fire Onclick event VB.Net


I have followed some of the instructions to create a new LinkButton at runtime with an event trigger and add an event handler for the LinkButton generated. I have no idea why the new LinkButton does not trigger the event added to it. Anyone please guide/correct me.

This is what I have right now.

ASPX:


 

 

 

 

    
        
            

            

        

    
  
Case Number :
            
            


   

  


  

 
ASPX.VB:

Protected Overloads Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Session("tablecontent") IsNot Nothing Then
        mytab1 = CType(Session("tablecontent"), HtmlTable)
    End If
End Sub

Public Function checking() As Boolean

        Dim caseNo As Double
            Try
                caseNo = Convert.ToDouble((caseNumber.Text).Trim())
            Catch ex As Exception
            caseNo = 0
            End Try

        Dim r As New HtmlTableRow
        Dim c0 As New HtmlTableCell
        r.Cells.Add(c0)

        Dim but As New LinkButton
        but.ID = caseNo
        but.Text = caseNo.ToString()
        AddHandler but.Click, AddressOf LinkButton1_Click
        c0.Controls.Add(but)

        mytab1.Rows.Add(r)
        Session("tablecontent") = mytab1
        Return True
End Function

Protected Sub LinkButton1_Click(sender As Object, e As EventArgs)

    'My Code here

End Sub

Protected Sub btnOK1_Click(sender As Object, e As EventArgs)

asked May 9, 2015 in vbdotnet by rajesh
0 votes
19 views



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...