ItemCommand event not firing from a Repeater’s sub control

Posted: 06/04/2013


You have a control (like a Button, LinkButton, etc.) that is causing a PostBack inside of a Repeater but the ItemCommand event is not being fired.

Possible Cause #1:

If the repeater is rebound every PostBack (or at all), it will lose the state of the button that was clicked. Say you load the repeater everytime the form loads, it would destroy the information needed to complete the ItemCommand.

Solution #1:

Load your data into the Repeater on the initial page load by checking IsPostBack in the form’s load. Only refresh the Repeater after the ItemCommand has been fired or at the end of the page life cycle.

Possible Cause #2 / Solution #2:

The Repeater may not have the ItemCommand wired up, either via a Handles or in the ASP markup. You only want to wire up the event in one of the two locations (otherwise, it will run twice). Here is an example of how to do this with VB syntax (with the pages AutoEventWireup = False):


    Protected Sub rptUnapproved_ItemCommand(source As Object, e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles rptUnapproved.ItemCommand
        Select Case e.CommandName
            Case "approve"
                ' e.CommandArgument
            Case "decline"
        End Select
    End Sub