views:

111

answers:

1

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?

A: 

Hey,

To bubble up events, you can have the user control define the event:

public event SomeEventHandler UpClicked;

Which references this:

public class SomeEventArgs {
   public ListItem Selected { get; set; }
}
public delegate void SomeEventHandler(object sender, SomeEventArgs e);

Which you can store more than one property here; you can store as many details as you like. But you can use this event arg to pass all the information to the page... it could be the issue is how you are calling the event; make sure in your user control you do something like:

public event SomeEventHandler UpClicked;

protected void OnUpClicked(SomeEventArgs e)
{
   if (UpClicked != null) UpClicked(this, e);
}

protected void button_click(object sender, EventArgs e)
{
    this.OnUpClicked(new SomeEventArgs { Selected = this.list.SelectedItem; });
}

HTH.

Brian
This is a VB.Net project but that's about what I've got (sorry for the formatting) - Public Event UpClicked As System.EventHandler Public Event DownClicked 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 SubAnd the code above, which is what's alternately getting the correct object and the wrong one coming through, in apparent strict rotation...
eftpotrm
Not sure I understand what you mean by that? Is ScriptListItem the user control? What should the up/down clicked events be passing so that you can change the order? Are you moving around the ASP.NET ListItem class, or your own custom one?
Brian
ScriptListItem is the name of the user control, which has a whole range of properties - it's nothing to do with the ListItem class. The UpClicked event should be passing Me as the first property, but Me is alternately coming through as the correct row and an adjacent row from checking its general properties.
eftpotrm
This has me a little confused as to what you mean by this "Me is alternately coming through as the correct row and an adjacent row from checking its general properties"... could you update your post to include this in the code sample?
Brian
Thanks for your persistence Brian - duly updated.
eftpotrm
Question clarified today after further testing, still no solution unfortunately.
eftpotrm