Skip to content

Custom Server Control - Button Click Event

Justin

Asked May 13, 2008, 1:07 PM EDT2 answers
Share
LinkedInX

I cannot get the button event inside my custom server control to raise. Below is an example written in 3.5. I believe my events are in order from examples listed online. Any help?

[ToolboxData("<{0}:TestButton runat=server></{0}:TestButton>")]public class TestButton : WebControl

C#
{
public Button Tester { get; set; }
public Label ClickedIndicator { get; set; }
protected override void CreateChildControls()
{
   base.CreateChildControls();
   Tester = new Button();
   Tester.ID = "btnTest";
   Tester.Text = "Increment Count";   Tester.Click += new EventHandler(Tester_Click);
   this.Controls.Add(Tester);

   ClickedIndicator = new Label();
   ClickedIndicator.ID = "lblClickCount";
   ClickedIndicator.Text = "not clicked";
   this.Controls.Add(ClickedIndicator);
}
protected void Tester_Click(object sender, EventArgs e)
{
   ClickedIndicator.Text = "clicked";
}

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    I resolved this issue by deriving my control from "CompositeControl" instead of "WebControl". Hope this is helpful to the next victim!

    0
  • 0
    Very helpful 7 years later thanks!!!!!!
    0