views:

723

answers:

2

Say I have a composite control in ASP.NET (C#) which includes a drop down list. I need to be able to bubble the event back to the parent form so that other code can be executed based on its SelectedItem.

How do I expose the OnSelectedItemChanged event to the application?

Do I need to create my own delegate and raise it when the internal drop down list item is changed?

+4  A: 

I've created control which contains a button and I'm using same approach; create a delegate and raise events on button's click.

public delegate void IndexChangeEventHandler(object sender, EventArgs e); 
public event IndexChangeEventHandler SelectedIndexChanged =  delegate { };

//this is in your composite control, handling ddl's index change event
protected void DDL_SelectedIndexchanged(object sender, EventArgs e)
{
    SelectedIndexChanged(this, e);
}
TheVillageIdiot
Thats exactly what I thought, thanks!
Mauro
A: 

Correct... You would want to create your own event for SelectedItem and write an event handler for the dropdown list's SelectedItem and inside the method raise your event.

J.13.L