Organizational Research By

Surprising Reserch 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.









Case Number :





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
                caseNo = Convert.ToDouble((caseNumber.Text).Trim())
            Catch ex As Exception
            caseNo = 0
            End Try

        Dim r As New HtmlTableRow
        Dim c0 As New HtmlTableCell

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

        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

Related Hot Questions

1 Answer

0 votes

When you click on the "Save" button, save the data in either local storage or database and try to load the page again to fill the page with the content from the storage. In this case, you can have the content on the page and so, you can utilize the events also.

answered May 9, 2015 by rajesh