Every user control inherits from System.Web.UI.U serControl which exposes a
method called RaiseBubbleEven t. 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_Sel ectedIndexChang ed(Object sender,EventArg s e)
{
CommandEventArg s ee = new CommandEventArg s("CountryChang e", null);
RaiseBubbleEven t(sender, ee);
}
override protected bool OnBubbleEvent(o bject sender, System.EventArg s e)
{
bool isHandled = false;
if(e is CommandEventArg s)
{
CommandEventArg s ee = (CommandEventAr gs)e;
switch(ee.Comma ndName)
{
case "CountryChange" :
ddlStates.Count ryCode = ddlCountries.Se lectedCountry;
ddlStates.DataB ind();
isHandled = true;
break;
}
}
return isHandled;
}
You can find lots of documentation on this in msdn help
smc750
http://www.certdev.com
VMI wrote:
My aspx has a user Control (a .ascx) that includes all the fields of an
address (add1, city, st, etc...). How can I add an event handler to a
comboBox inside the .ascx from within my aspx page? I just want to add this
event handler to that instance of the comboBox.
Thanks.
--
Message posted via
http://www.dotnetmonster.com