tags:

views:

509

answers:

2

I have a CompositeDataBoundControl and im trying to add a ItemCommand to it, ala the System.Web.UI.WebControls.Repeater - so like a numpty, I just thought if I reflector'ed and added the code like so, it should work:

private static readonly object EventItemCommand = new object();

protected override bool OnBubbleEvent(object sender, EventArgs e)
{

   // throw new Exception();
    bool flag = false;
    if (e is RepeaterCommandEventArgs)
    {
        this.OnItemCommand((RepeaterCommandEventArgs)e);
        flag = true;
    }
    return flag;
}


protected virtual void OnItemCommand(RepeaterCommandEventArgs e)
{
    RepeaterCommandEventHandler handler = (RepeaterCommandEventHandler)base.Events[EventItemCommand];
    if (handler != null)
    {
        handler(this, e);
    }
}

public event RepeaterCommandEventHandler ItemCommand
{
    add
    {
        base.Events.AddHandler(EventItemCommand, value);
    }
    remove
    {
        base.Events.RemoveHandler(EventItemCommand, value);
    }
}

Unfortunatly, even though I have the event bound, it does not seem to fire. Iv tried to go down the route of IPostBackEventHandler, but its still not quite right (I can fire an empty event off with no args, but I cant see a decent way to call the OnItemCommand with the RepeaterCommandEventArgs

Any ideas how to get this to work?

Iv been sitting on the office for the last 4 hours trying to get this to work! Help!

+2  A: 

In the case of the Repeater control the RepeaterItem object is actually raising the bubble event and supplying the RepeaterCommandEventArgs:

protected override bool OnBubbleEvent(object source, EventArgs e)
{
    if (e is CommandEventArgs)
    {
        RepeaterCommandEventArgs args = new RepeaterCommandEventArgs(this, source, (CommandEventArgs) e);
        base.RaiseBubbleEvent(this, args);
        return true;
    }
    return false;
}

In case you are not using the RepeaterItem in your control you will probably never get that RepeaterCommandEventArgs. Try checking for CommandEventArgs instead. Also make sure the OnBubbleEvent method of your control is ever called.

korchev
A: 

Im using a custom "RepeaterItem" (eg. RecipeItem) - I cant seem to get the OnBubbleEvent (have overriden it and stole things from RepeaterItem) to fire in the item.

Nevermind, im an idiot. Commented out a DataBind();!

pzycoman