Nate
Nate

Reputation: 2326

Dynamic link button not firing in update panel

I'm dynamically adding a link button in the footer of a grid view. The grid view is wrapped in an update panel. I can get an async post back (I can tell by seeing an update progress flash), but I can't get the debug point in my click function to fire.

Private Sub gvParts_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvParts.RowDataBound
 ElseIf e.Row.RowType = DataControlRowType.Footer Then
        If _showPrice Then

            Dim clearbutton As New LinkButton
            clearbutton.ID = "btnClearCart"
            clearbutton.Text = "Remove All"

            ScriptManager1.RegisterAsyncPostBackControl(clearbutton)
            e.Row.Cells(7).Controls.Add(clearbutton)

            AddHandler clearbutton.Command, AddressOf clearButton_click

        End If
    End If

Private Sub clearButton_click(ByVal sender As Object, ByVal e As System.EventArgs)
    ClearCart()
End Sub

Upvotes: 1

Views: 2031

Answers (2)

Al W
Al W

Reputation: 7713

The controls have to be added to your Controls collection prior to the page_load event. The default databinding (which fires the OnRowCreated, OnRowDataBound events) happens during the OnLoad event. Try moving your databinding code to the Page_Init function. Depending on what your databinding code looks like, this might mean you will have to implement the databinding "manually" (ie. Set the datasource and call .DataBind() in code)

Upvotes: 0

santosh singh
santosh singh

Reputation: 28642

try this

<dl>




Private Sub gvParts_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvParts.RowDataBound
     ElseIf e.Row.RowType = DataControlRowType.Footer Then
            If _showPrice Then

                Dim clearbutton As New LinkButton
                clearbutton.ID = "btnClearCart"
                clearbutton.Text = "Remove All"

                ScriptManager1.RegisterAsyncPostBackControl(clearbutton)
                e.Row.Cells(7).Controls.Add(clearbutton)

                AddHandler clearbutton.Command, AddressOf clearButton_click

    ScriptManager.GetCurrent(Me).RegisterAsyncPostBackControl(clearbutton)

            End If
        End If

Sorry,It's my mistake I have posted wrong code.Place the above code on OnRowCreated event of gridview

try this

  Private Sub gvParts_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvParts.RowDataBound
     ElseIf e.Row.RowType = DataControlRowType.Footer Then
            If _showPrice Then

                Dim clearbutton As New LinkButton
                clearbutton.ID = "btnClearCart"
                clearbutton.Text = "Remove All"

                ScriptManager1.RegisterAsyncPostBackControl(clearbutton)
                e.Row.Cells(7).Controls.Add(clearbutton)

                AddHandler clearbutton.Command, AddressOf clearButton_click

    ScriptManager.GetCurrent(Me).RegisterAsyncPostBackControl(clearbutton)

            End If
        End If

Upvotes: 1

Related Questions