ASP.Net event only being raised every other time?

Posted by eftpotrm on Stack Overflow See other posts from Stack Overflow or by eftpotrm
Published on 2010-03-09T10:57:15Z Indexed on 2010/03/12 14:47 UTC
Read the original article Hit count: 218

I have an ASP.Net web user control which represents a single entry in a list. To allow users to reorder the items, each item has buttons to move the item up or down the list. Clicking on one of these raises an event to the parent page, which then shuffles the items in the placeholder control.

Code fragments from the list entry:

Public Event UpClicked As System.EventHandler
Protected Sub btnUp_Click(ByVal sender As Object, ByVal e As System.EventArgs)
              Handles btnUp.Click
    RaiseEvent UpClicked(Me, New EventArgs())
End Sub

And the parent container:

    rem (within the code to add an individual item to the placeholder)
    AddHandler l_oItem.UpClicked, AddressOf UpClicked


Protected Sub UpClicked(ByVal sender As Object, ByVal e As EventArgs)
    MoveItem(DirectCast(sender, ScriptListItem), -1)
End Sub

It originally looked in testing like every other time the value for sender (verified by its properties) that reaches UpClicked is of an adjacent ListItem, not the one I've just clicked on - the first click is always wrong, then the second for the correct control.

At present, testing appears to show that the button's click event is just being ignored every other time through. Breakpoints on the click events within the control simply aren't being hit, though the events are definitely being established.

Why?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about vb.net