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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mauro
  • 4,531
  • 3
  • 30
  • 56

2 Answers2

5

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
  • 40,053
  • 20
  • 133
  • 188
0

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.

bytebender
  • 7,371
  • 2
  • 31
  • 54