locked
LinkButton Click Event not Firing Inside of Custom GridView RRS feed

  • Question

  • User-224732036 posted

    I have a GridView that I populate with custom template fields. In some of the template fields I add a Link Button. Everything is working find except for when I click on the Link Button it doesn't fire the event. I have been having this problem for a while where LinkButtons created dynamically within Server Controls don't fire their Click event properly.

     Public Sub New(ByVal t As ListItemType, ByVal d As DataColumn, ByRef e() As EventHandler)
            type = t
            dc = d
            events = e
        End Sub
    
        Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
    
            Dim linkButton As LinkButton
            Dim label As Label
    
            Select Case type
    
                Case ListItemType.Item
    
                    If dc.ColumnName.Equals("serialNumber") Or dc.ColumnName.Equals("modelName") Or dc.ColumnName.Equals("productType") Or
                        dc.ColumnName.Equals("tubeSN") Or dc.ColumnName.Equals("tubeModelName") Then
    
                        linkButton = New LinkButton()
                        linkButton.ID = "lb" + dc.ColumnName
                        linkButton.CommandName = dc.ColumnName
                        AddHandler linkButton.Click, events(0)
                        AddHandler linkButton.DataBinding, New EventHandler(AddressOf dataBindingHandler)
                        container.Controls.Add(linkButton)
    
                    Else
    
                        label = New Label()
                        label.ID = "lbl" + dc.ColumnName
                        AddHandler label.DataBinding, New EventHandler(AddressOf dataBindingHandler)
    
                    End If
    
    
                Case ListItemType.EditItem
    
    
    
    
    
                Case Else
    
    
    
            End Select
    
        End Sub
    Thursday, July 14, 2011 3:51 PM

Answers

  • User-16411453 posted
    AddHandler linkButton.Click, Addressof linkbutton_Click


    Protected Sub linkbuton_Click(
    ByVal sender As Object, ByVal e As System.EventArgs)

    If page.ispostback Then

    End if

    End Sub
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 17, 2011 1:33 AM

All replies

  • User-2010311731 posted

    Here is a reference that should help...

    http://authors.aspalliance.com/articles/dynamicbuttons.aspx

     

    Matt

     

    Thursday, July 14, 2011 4:08 PM
  • User-224732036 posted

    That helps a lot but I'm still having an issue with not being able to determine what DataTable to generate. This is because the DataTable that is bound to the GridView is dynamically created depending on what the user does. I need some way to save the state of that previous request in order to recreate the GridView as it was on Page Load. What would the best way to do this be? Text document? Cookie? Something else entirely?

    Friday, July 15, 2011 11:29 AM
  • User3866881 posted

    What would the best way to do this be? Text document? Cookie? Something else entirely?

    Hello:)

    Considering it that you are now using DataTable for each one, Maybe Session or ViewState is your choice.

    Saturday, July 16, 2011 11:05 PM
  • User-16411453 posted
    AddHandler linkButton.Click, Addressof linkbutton_Click


    Protected Sub linkbuton_Click(
    ByVal sender As Object, ByVal e As System.EventArgs)

    If page.ispostback Then

    End if

    End Sub
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 17, 2011 1:33 AM