Composite control events dont fire.

A

Arthur Puszynski

Hello,

I cannot figure out why this doesnt work. This is almost exactly the same as
the samples I've seen but it doesnt work for me.

I am making a composite control with a button that has a click event but the
event never fires.
Here's my code:

public class WebCustomControl1 : System.Web.UI.WebControls.WebControl
{

protected override void CreateChildControls()
{
Button sButton = new Button();
sButton.Click +=new EventHandler(sButton_Click);
Controls.Add(sButton);
base.CreateChildControls ();
}

protected override void Render(HtmlTextWriter output)
{
Controls[0].RenderControl(output);
}

private void sButton_Click(object sender, EventArgs e)
{
((Button)Controls[0]).Text = "Clicked";

}

}

Any ides?

Thank you,

Art
 
A

Arthur Puszynski

Excellent Thank You!


Teemu Keiski said:
Implement INamingContainer interface in the control.

--
Teemu Keiski
MCP, Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com

Arthur Puszynski said:
Hello,

I cannot figure out why this doesnt work. This is almost exactly the
same
as
the samples I've seen but it doesnt work for me.

I am making a composite control with a button that has a click event but the
event never fires.
Here's my code:

public class WebCustomControl1 : System.Web.UI.WebControls.WebControl
{

protected override void CreateChildControls()
{
Button sButton = new Button();
sButton.Click +=new EventHandler(sButton_Click);
Controls.Add(sButton);
base.CreateChildControls ();
}

protected override void Render(HtmlTextWriter output)
{
Controls[0].RenderControl(output);
}

private void sButton_Click(object sender, EventArgs e)
{
((Button)Controls[0]).Text = "Clicked";

}

}

Any ides?

Thank you,

Art
 
T

Tom K

Arthur,

Did this fix your problem? I have a similiar problem when
inheriting from DataGrid and trying to render buttons
above the grid. Renders fine but cannot catch the events.
I have implmented INamingContainer but
it did not seem to help.

Tom

-----Original Message-----
Excellent Thank You!


Teemu Keiski said:
Implement INamingContainer interface in the control.

--
Teemu Keiski
MCP, Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com
almost exactly the
same
as
the samples I've seen but it doesnt work for me.

I am making a composite control with a button that
has a click event but
the
event never fires.
Here's my code:

public class WebCustomControl1 : System.Web.UI.WebControls.WebControl
{

protected override void CreateChildControls()
{
Button sButton = new Button();
sButton.Click +=new EventHandler(sButton_Click);
Controls.Add(sButton);
base.CreateChildControls ();
}

protected override void Render(HtmlTextWriter output)
{
Controls[0].RenderControl(output);
}

private void sButton_Click(object sender, EventArgs e)
{
((Button)Controls[0]).Text = "Clicked";

}

}

Any ides?

Thank you,

Art


.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top