Every user control inherits from System.Web.UI.UserControl which exposes a
method called RaiseBubbleEvent. You do not necessarily have to make your
controls public. You can just call this method from your user control and
have the hosting page or control handle it through the protected method
OnBubbleEvent. Below is some example code where you can raise an event from a
custom dropdownlist control and the handle the event in the hosting page.
/// <summary>
/// Raises a custom event to the user of the control
/// if you want to sync this control with another.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ddCountries_SelectedIndexChanged(Object sender,EventArgs e)
{
CommandEventArgs ee = new CommandEventArgs("CountryChange", null);
RaiseBubbleEvent(sender, ee);
}
override protected bool OnBubbleEvent(object sender, System.EventArgs e)
{
bool isHandled = false;
if(e is CommandEventArgs)
{
CommandEventArgs ee = (CommandEventArgs)e;
switch(ee.CommandName)
{
case "CountryChange":
ddlStates.CountryCode = ddlCountries.SelectedCountry;
ddlStates.DataBind();
isHandled = true;
break;
}
}
return isHandled;
}
You can find lots of documentation on this in msdn help
smc750
http://www.certdev.com