Hi Jeffrey.
""Jeffrey Tan[MSFT]"" <v-jetan@online.microsoft.com> wrote in message
news:bxHHiov5DHA.1992@cpmsftngxa07.phx.gbl...
>
> Hi Casper,
>
> Thank you for posting in the community!
>
> Based on my understanding, you are building a custom control, in which you
> created several child controls. Althrough you have added event handler for
> your child control, this event handle does not take effect.
>
> ===================================================
> Where do you create your child controls? Do you create your child control
> through override Control.CreateChildControls?
>
> Acutally, in Composite Control, if you want to hook the child controls'
> event, you must implement the System.Web.UI.INamingContainer interface. It
> will provide you the unique names in the hierarchical tree of controls. If
> you do not implement this interface, asp.net model will not associate the
> event handler well.
>
> For example, this code will work well:
> using System;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.ComponentModel;
>
> namespace CustomControls
> {
> public class EventBubbler : System.Web.UI.WebControls.WebControl,
> INamingContainer
> {
> protected override void CreateChildControls()
> {
> Button button1 = new Button();
> button1.Text = "Click";
> button1.Click+=new EventHandler(button1_Click);
> Controls.Add(button1);
> }
>
> private void button1_Click(object sender, EventArgs e)
> {
> this.Page.Response.Write("Child button event fires");
> }
> }
> }
>
> But this will not fire your event:
> using System;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.ComponentModel;
>
> namespace CustomControls
> {
> public class EventBubbler : System.Web.UI.WebControls.WebControl
> {
> protected override void CreateChildControls()
> {
> Button button1 = new Button();
> button1.Text = "Click";
> button1.Click+=new EventHandler(button1_Click);
> Controls.Add(button1);
> }
>
> private void button1_Click(object sender, EventArgs e)
> {
> this.Page.Response.Write("Child button event fires");
> }
> }
> }
>
> For more information, please refer to "Developing a Composite Control" at:
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
> l/cpcondevelopingcompositecontrols.asp
>
> ================================================================
> Please apply my suggestion above and let me know if it helps resolve your
> problem.
>
> Thank you for your patience and cooperation. If you have any questions or
> concerns, please feel free to post it in the group. I am standing by to be
> of assistance.
> Have a nice day!!
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! -
www.microsoft.com/security > This posting is provided "as is" with no warranties and confers no rights.
>