Why dont you expose some event from the user Control?
Say you expose events like DropDown1SelectedIndexChanged, DropDown2SelectedIndexChanged etc and raise them when the actual event occurs.
To expose an event you need to declare a delegate. Like this :
public delegate void DropDownSelectionChanged(object sender, SelectionChangeEventArgs e);
Define an Event :
public event DropDownSelectionChanged DropDown1SelectedIndexChanged;
public event DropDownSelectionChanged DropDown2SelectedIndexChanged;
You also need to define some virtual methods to check whether the event raised actually added to any handler. To do this Use:
public virtual void OnDropDown1SelectionChanged(object sender, SelectionChangeEventArgs e)
{
if(this.DropDown1SelectedIndexChanged != null)
this.DropDown1SelectedIndexChanged(sender, e);
}
public virtual void OnDropDown2SelectionChanged(object sender, SelectionChangeEventArgs e)
{
if(this.DropDown2SelectedIndexChanged != null)
this.DropDown2SelectedIndexChanged(sender, e);
}
Finally in the actual SelectedIndexChanged event :
protected void dropdown1_selectedIndexChanged(object sender, EventArgs e)
{
SelectionChangeEventArgs eventargs = new SelectionChangedEventArgs(dropdown1.SelectedItem);
this.OnDropDown1SelectionChanged(this, eventArgs);
}
For this you also need to define a custom class SelectionChangeEventArgs.
public class SelectionChangeEventArgs
{
public SelectionChangeEventArgs(ListItem li)
{
this.SeletedItem = li;
}
public ListItem SelectedItem
{ get; set;}
}
Now fianlly in the calling environment, you need to add one eventhandler for DropDown1SelectionChanged and do whatever you want.
Also modify the class SelectionChangeEventArgs to define the items you need to pass into the calling environment.
www.abhisheksur.com
Chandan.sahab, if this helps please login to Mark As Answer. | Alert Moderator