composite control does not fire event

Discussion in 'ASP .Net Building Controls' started by Patrick, Jul 15, 2005.

  1. Patrick

    Patrick Guest

    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");
    }

    }
     
    Patrick, Jul 15, 2005
    #1
    1. Advertising

  2. Patrick

    Patrick Guest

    no, it was easier, just had to implement the INamingContainer Interface, now
    it works


    "intrader" <> schrieb im Newsbeitrag
    news:p...
    > On Fri, 15 Jul 2005 21:28:08 +0200, Patrick wrote:
    >
    >> 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");
    >> }
    >>
    >> }

    > I am assuming that you don't see the "button was clicked" message.
    > Is bubbling to the page your problem?
    >
    >
     
    Patrick, Jul 19, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    740
  2. C. Ramsey

    Composite Control datagrid event does not fire

    C. Ramsey, Sep 12, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    170
    Teemu Keiski
    Sep 15, 2003
  3. Chad
    Replies:
    0
    Views:
    243
  4. Joe Abou Jaoude

    How to fire a client event from a composite control

    Joe Abou Jaoude, Jul 3, 2007, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    793
    Sergey Poberezovskiy
    Jul 4, 2007
  5. Patrick

    composite control does not fire event

    Patrick, Jul 18, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    155
    Steve Walker
    Jul 18, 2005
Loading...

Share This Page