Home All Groups Group Topic Archive Search About

composite control does not fire event

Author
18 Jul 2005 7:35 AM
Patrick
Hi

I have an aspx-page, where I load my custom-control (see below). The problem
I have is that the event does not fire. I really cant figure out why. Just
to know, I derive from System.Web.UI.Control, becaues later on I want to add
some more controls, but first I have to solve this problem.

Has someone an idea?

Thanks
Patrick


*************** default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
    Control ctrl = new Mycustomcontrol();
    this.form1.Controls.Add(ctrl);
}


*************** Mycustomcontrol.cs
public class Mycustomcontrol: System.Web.UI.Control
{
    private Button bt;

    protected override void CreateChildControls()
    {

        bt = new Button();
        bt.Text = "test";
        this.Controls.Add(bt);
        bt.Click += new EventHandler(bt_Click);
    }

    protected void bt_Click(object sender, EventArgs e)
    {
        System.Web.HttpContext.Current.Response.Write("button was clicked");
    }

}

Author
18 Jul 2005 10:57 AM
Steve Walker
In message <e7kVZt2iFHA.1***@TK2MSFTNGP12.phx.gbl>, Patrick
<patrick***@bluemail.ch> writes
>Hi
>
>I have an aspx-page, where I load my custom-control (see below). The problem
>I have is that the event does not fire. I really cant figure out why. Just
>to know, I derive from System.Web.UI.Control, becaues later on I want to add
>some more controls, but first I have to solve this problem.

Add the marker interface INamingContainer to your control.


--
Steve Walker
Author
18 Jul 2005 2:26 PM
Patrick
Hi Steve

Thanks, that was the problem :-)

Patrick

Show quoteHide quote
"Steve Walker" <st***@otolith.demon.co.uk> schrieb im Newsbeitrag
news:tb58ZgN2s42CFwHa@otolith.demon.co.uk...
>
>
> In message <e7kVZt2iFHA.1***@TK2MSFTNGP12.phx.gbl>, Patrick
> <patrick***@bluemail.ch> writes
>>Hi
>>
>>I have an aspx-page, where I load my custom-control (see below). The
>>problem
>>I have is that the event does not fire. I really cant figure out why. Just
>>to know, I derive from System.Web.UI.Control, becaues later on I want to
>>add
>>some more controls, but first I have to solve this problem.
>
> Add the marker interface INamingContainer to your control.
>
>
> --
> Steve Walker
Author
18 Jul 2005 3:59 PM
Steve Walker
In message <OIWm3S6iFHA.1***@TK2MSFTNGP10.phx.gbl>, Patrick
<patrick***@bluemail.ch> writes
Show quoteHide quote
>> In message <e7kVZt2iFHA.1***@TK2MSFTNGP12.phx.gbl>, Patrick
>> <patrick***@bluemail.ch> writes
>"Steve Walker" <st***@otolith.demon.co.uk> schrieb im Newsbeitrag
>news:tb58ZgN2s42CFwHa@otolith.demon.co.uk...

>>>I have an aspx-page, where I load my custom-control (see below). The
>>>problem
>>>I have is that the event does not fire. I really cant figure out why. Just
>>>to know, I derive from System.Web.UI.Control, becaues later on I want to
>>>add
>>>some more controls, but first I have to solve this problem.

>> Add the marker interface INamingContainer to your control.

>Thanks, that was the problem :-)

You're welcome. I write controls all the time, and that one still bites
me now and then.

--
Steve Walker