N
Nidhee
Hi Everyone,
I am building a composite server control. I have defined an event for
my child control with Custom Event Arguments. I am using the bubbling
method to access the child control's events in the Parent control.
Still, my child control is not raising the event. What am I missing?
Following is the code snippet:
//Child control code
public class ChildClass: System.Web.UI.WebControls.WebControl,
ISerializable, IPostBackEventHandler, INamingContainer
{
public event CustomEventHandler DoubleClick;
protected override void Render(HtmlTextWriter writer){ ... }
#region IPostBackEventHandler Members
public void RaisePostBackEvent(string eventArgument)
{
CustomEventArgs cusArgs = new CustomEventArgs(this.PKID);
if (DoubleClick != null)
{
DoubleClick(this, cusArgs);
RaiseBubbleEvent(this, cusArgs);
}
}
#endregion
#region CustomEventArgs class
//CustomEventArgs class
public class CustomEventArgs: EventArgs
{
public CustomEventArgs(int PKID)
{
this.PKID = PKID;
}
public int PKID;
} //end of class RectangleEventArgs
#endregion
}
//Parent control code
public class ParentClass : System.Web.UI.WebControls.WebControl,
IPostBackEventHandler
public event CustomEventHandler GetCustomProperties;
protected override void CreateChildControls() { ... }
protected override bool OnBubbleEvent(object source, EventArgs args)
{
bool handled = false;
if(GetCustomProperties != null)
if(args is CustomEventArgs)
{
CustomEventArgs e = (CustomEventArgs)args;
GetCustomProperties(this, e);
handled = true;
}
return handled;
}
I am building a composite server control. I have defined an event for
my child control with Custom Event Arguments. I am using the bubbling
method to access the child control's events in the Parent control.
Still, my child control is not raising the event. What am I missing?
Following is the code snippet:
//Child control code
public class ChildClass: System.Web.UI.WebControls.WebControl,
ISerializable, IPostBackEventHandler, INamingContainer
{
public event CustomEventHandler DoubleClick;
protected override void Render(HtmlTextWriter writer){ ... }
#region IPostBackEventHandler Members
public void RaisePostBackEvent(string eventArgument)
{
CustomEventArgs cusArgs = new CustomEventArgs(this.PKID);
if (DoubleClick != null)
{
DoubleClick(this, cusArgs);
RaiseBubbleEvent(this, cusArgs);
}
}
#endregion
#region CustomEventArgs class
//CustomEventArgs class
public class CustomEventArgs: EventArgs
{
public CustomEventArgs(int PKID)
{
this.PKID = PKID;
}
public int PKID;
} //end of class RectangleEventArgs
#endregion
}
//Parent control code
public class ParentClass : System.Web.UI.WebControls.WebControl,
IPostBackEventHandler
public event CustomEventHandler GetCustomProperties;
protected override void CreateChildControls() { ... }
protected override bool OnBubbleEvent(object source, EventArgs args)
{
bool handled = false;
if(GetCustomProperties != null)
if(args is CustomEventArgs)
{
CustomEventArgs e = (CustomEventArgs)args;
GetCustomProperties(this, e);
handled = true;
}
return handled;
}